Referencing methods via iterators
-
I have a class called curves and an stl::list of them called curveList. class curve { int getValue(); . . . } ; typedef std::list::iterator curveItr; class curveList { public: curveItr getCurveByID(ID i); . private: std::list _myList . } in my code, I declare curveItr iter; iter = myCurveList.getCurveByID(1); // this returns the correct iterator I get the right value back. Now I want to use iter to call a function of curve to return a value (I'm trying to avoid casting as pointers, list of pointers, etc). Everything I do throws a LINK error LNK2019 unresolved external. I have tried iter->getValue(); *iter.getValue(); &(*iter)->getValue(); p = static_cast(iter) but everything throws back the same error. Is there a correct way to do this or do i have to resort to lists of pointers? BTW, the curve/type declarations are in a separate file from getCurveByID is called.
-
I have a class called curves and an stl::list of them called curveList. class curve { int getValue(); . . . } ; typedef std::list::iterator curveItr; class curveList { public: curveItr getCurveByID(ID i); . private: std::list _myList . } in my code, I declare curveItr iter; iter = myCurveList.getCurveByID(1); // this returns the correct iterator I get the right value back. Now I want to use iter to call a function of curve to return a value (I'm trying to avoid casting as pointers, list of pointers, etc). Everything I do throws a LINK error LNK2019 unresolved external. I have tried iter->getValue(); *iter.getValue(); &(*iter)->getValue(); p = static_cast(iter) but everything throws back the same error. Is there a correct way to do this or do i have to resort to lists of pointers? BTW, the curve/type declarations are in a separate file from getCurveByID is called.
mjackson11 wrote:
Everything I do throws a LINK error LNK2019 unresolved external.
If it is a linker error, then it means that the code compiles fine. Besides, your first approach is the correct one (iter->getValue() ). The error specifies that you have decleared a function but you didn't provide any definition for it. I guess it is for the getValue function, am I right ? To fix the problem, simply provide a function body.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
mjackson11 wrote:
Everything I do throws a LINK error LNK2019 unresolved external.
If it is a linker error, then it means that the code compiles fine. Besides, your first approach is the correct one (iter->getValue() ). The error specifies that you have decleared a function but you didn't provide any definition for it. I guess it is for the getValue function, am I right ? To fix the problem, simply provide a function body.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++Stupid programming tricks -- the method was defined in a file that was in the directory but not included in the project. Two wasted days.