Adding objects to array in C++ -
in header.h:
before class: class treadmill;
private: treadmill* treadmilllist;
public: bool addtreadmill(treadmill *obj);
in header.cpp:
constructor: treadmilllist = new treadmill[listsize]; bool trainee::addtreadmill(treadmill *obj) { treadmilllist[numoftreadmills++]=obj; }
result of compiling:
treadmill.cpp: in member function ‘bool trainee::addtreadmill(treadmill*)’: treadmill.cpp:39:34: error: no match ‘operator=’ (operand types ‘treadmill’ , ‘treadmill*’) treadmilllist[numoftreadmills++]=obj; ^ treadmill.cpp:39:34: note: candidate is: in file included treadmill.cpp:3:0: treadmill.h:3:7: note: treadmill& treadmill::operator=(const treadmill&) class treadmill { ^ treadmill.h:3:7: note: no known conversion argument 1 ‘treadmill*’ ‘const treadmill&’
from looking @ code posted think trying store treadmill pointers, or addresses treadmill objects in array of type treadmill. if want store pointers type treadmill in array try:
treadmill** treadmilllist; constructor: treadmilllist = new treadmill*[listsize];
this based on observed though didnt state aiming , problem exactly.
Comments
Post a Comment