c++ - Not understanding how pointers and classes work together in this example -
hmmmm stumped on one, using visual studio 2012 have 1 error left on project , dying test out. yes it's c++ class , hope posted enough code.
i error:
c2227 left of ->writedata must point class/struct/union/generic type
in previous project line had element of array of pointers ( employee* pointer assume) , worked so:
employee* myemployees[max_emps]; ... myemployees[i]->writedata(outputemployee);
so implement vector of employee*, , assume contains pointers:
myvector<employee*> employeeptrlist;
i next couple steps bit indirectly have cleared prof. debry:
employee* empptr1 = new hourlyemployee(emp1_id, emp1_name, emp1_address, emp1_phone, emp1_hours, emp1_wage); 2... 3... 4... employeeptrlist.push_back(empptr1); 2... 3... 4...
then later in program line giving me error:
employeeptrlist.at(i)->writedata(outputemployee);
i have tried various things, if dereference *(employeeptrlist) fun changes intellisense error still same:
c2227 left of ->writedata must point class/struct/union/generic type
any idears? stumped understand employeeptrlist employee pointer maybe it's looking @ in wrong class? guess maybe not "pointing" function in myvector class properly?
thanks
without knowing how myvector
works, few things @ first glance going wrong:
.at()
might returning reference object (or copy of object), you'd need use .
operator.
another possibility that, if .at()
returns iterator of type employee*
, might need dereference iterator (i.e. (*employeeptrlist.at(i))->writedata(outputemployee);
) depending on implementation.
Comments
Post a Comment