Thread: Linker Error problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Thanks for the help!
    Er...any idea why it won't let me use cout<< on the vector?
    I tried:
    Code:
    cout<<PVec.begin();
    and
    Code:
    cout<<PVec.end()-1;
    but I keep getting an error about there not being a match for it. This is in the function PhoneBook::AddPerson(); by the way.
    To code is divine

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    Because you have spots in your vector that contain NULL pointers because no memory has been allocated to your person pointer.

    Code:
    person *npb;
    should be:
    Code:
    person *npb = new person;
    Make sure that when you declare a pointer, that before you use the pointer and store variables in its location that you need to assign the memory using the new operator.
    Last edited by JoshR; 06-06-2005 at 08:06 AM.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    PVec.begin() is an iterator (basically a pointer) to type person. If you had overloaded the stream insertion operator (<<) for type person and you changed the way you were outputting from:

    Code:
    cout << PVec.begin();
    to:

    Code:
    cout << *PVec.begin();
    then it should work.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    *this
    Join Date
    Mar 2005
    Posts
    498
    Quote Originally Posted by hk_mp5kpdw
    then it should work.
    It would just output a 0 because he hasnt assigned memory to the location, so theres no way his variables made it to the location of the pointer.

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by JoshR
    It would just output a 0 because he hasnt assigned memory to the location, so theres no way his variables made it to the location of the pointer.
    I already made mention of the fact the OP was not allocating memory to the npb pointer in my first post. I am assuming he corrected that and has now moved on to another seperate issue.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker problem... no idea
    By cyreon in forum C Programming
    Replies: 2
    Last Post: 04-03-2009, 02:53 PM
  2. linker
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 02-23-2008, 01:25 AM
  3. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  4. Linker errors when compiling
    By The Wazaa in forum C++ Programming
    Replies: 4
    Last Post: 10-07-2006, 12:55 PM
  5. MSVis-Studio C++ libraries and linker errors
    By kellydj in forum Windows Programming
    Replies: 10
    Last Post: 03-12-2002, 02:03 PM