-
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
-
>> undefined reference to `project::vector<int, 3u>::vector(project::vector<int, 3u> const&)
That's the copy constructor. It's missing.
gg
-
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.