Domanda

Hmmmm I am stumped on this one, using Visual Studio 2012 I have only one error left on my project and I am dying to test it out. Yes it's for a C++ class and I hope I posted enough code.

I get the error:

C2227 left of ->writeData must point to class/struct/union/generic type

In the previous project this line had the element of the array of pointers ( an Employee* pointer I assume) and it worked like so:

Employee* myEmployees[MAX_EMPS];
...
myEmployees[i]->writeData(outputEmployee);

So I implement a vector of Employee*, and assume it also contains pointers:

MyVector<Employee*> employeePtrList;

I do the next couple steps a bit indirectly but have cleared this with 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 the program this line is giving me the error:

employeePtrList.at(i)->writeData(outputEmployee);

I have tried various things, if I dereference it with *(employeePtrList) just for fun it changes the intellisense error but I still get the same:

C2227 left of ->writeData must point to class/struct/union/generic type

Any idears? Where I get stumped is understand that employeePtrLIst is an Employee pointer so maybe it's looking for at in the wrong class? I guess maybe I am not "pointing" to the function in the MyVector class properly?

Thanks

È stato utile?

Soluzione

Without knowing exactly how MyVector works, a few things at first glance could be going wrong:

.at() might be returning a reference to an object (or even a copy of the object), thus you'd need to use the . operator.

Another possibility is that, if .at() returns an iterator of type Employee*, you might need to dereference the iterator (i.e. (*employeePtrList.at(i))->writeData(outputEmployee);) depending on the implementation.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top