Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Referencing methods via iterators

Referencing methods via iterators

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mjackson11
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • M mjackson11

      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.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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++

      M 1 Reply Last reply
      0
      • C Cedric Moonen

        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++

        M Offline
        M Offline
        mjackson11
        wrote on last edited by
        #3

        Stupid programming tricks -- the method was defined in a file that was in the directory but not included in the project. Two wasted days.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups