Thread: help me to debug?

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    help me to debug?

    I've got the following error

    Code:
    vector_main.cpp:(.text._ZN6projectplIiLj3EEENS_6vectorIT_XT0_EEERKS3_S5_[project::vector<int, 3u> project::operator+<int, 3u>(project::vector<int, 3u> const&, project::vector<int, 3u> const&)]+0x20): undefined reference to `project::vector<int, 3u>::vector(project::vector<int, 3u> const&)'
    vector_main.cpp:(.text._ZN6projectplIiLj3EEENS_6vectorIT_XT0_EEERKS3_S5_[project::vector<int, 3u> project::operator+<int, 3u>(project::vector<int, 3u> const&, project::vector<int, 3u> const&)]+0x32): undefined reference to `project::vector<int, 3u>::vector(project::vector<int, 3u> const&)'
    I've attached my code to look into, I have no idea why this is

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> undefined reference to `project::vector<int, 3u>::vector(project::vector<int, 3u> const&)
    That's the copy constructor. It's missing.

    gg

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Some suggestions:
    I would actually declare all of the code for the vector class inside the class itself. It's a lot less problematic and much easier. That is most likely to solve your immediate problem, but read on...

    Implement +, - in terms of +=, -= rather than the other way around. This is partly because += should be more efficient than + etc, not the other way around.
    About your problem though, the code doesn't add up. You've declared "list" to be a fixed-length array yet the thing that looks like it's supposed to be your copy-constructor and destructor use delete[] and new[].

    Why is a "size" member needed when the size seems to always be equal to the template parameter "n".

    You should use the copy and swap idiom for your copy-constructor. There's a GotW article that explains why checking for self-assignment is a bad sign in a copy-constructor and why what you have is exception unsafe.

    The checkSize function could be done in one line:
    Code:
    return v1.size == v2.size
    Code:
    if (checkSize(v1,v2) != false)
    would be clearer as
    Code:
    if (checkSize(v1,v2))
    What about providing IOStream overloads for << and >> rather than simply providing a print function that specifically sends output to cout? Or at least make print a const function.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary not built with debug info - why?
    By ulillillia in forum C Programming
    Replies: 15
    Last Post: 12-11-2008, 01:37 AM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 04:00 PM
  3. Debug --> Exceptions in Visual Studio 2005
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2007, 02:12 AM
  4. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2002, 11:07 PM