template <class Item>
void dinorray::recapacitate()
{
dinorray temp(this);
data = new Item[(2 * get_capacity()) + 1 ];
capacity = (2 * get_capacity()) + 1;
//the endpoints of the following line may be faulty
copy(temp, temp + temp.get_capacity(), data);
}
Here is the command I use to compile:
g++ -c dinorray.cpp
When I attempt to compile my implementation file, I run into errors that indicate an incomplete communication between the implementation file and the header file. Whenever the function definitions try to access private member variables, the compiler says that the private member variable has not been defined. Whenever I type "dinorray::" in the implementation file, the compiler interprets the code as attempting to redefine the dinorray class.
How can I get these two files to talk to each other?
First can you post your code in code tags - the <> button on the right under format. The code is a nightmare to read otherwise. Do separate code tags for each file.
Next post your compiler output, it's easier to deal with than 200 lines of code. When you do that, the line numbers in the compiler output won't match those in the code tags because they start at 1, so can you let us know which lines match up.
I think that templates can be used in source files in c++11 (I remember reading something about that). But I don't know anything about that new syntax or how to do it.
But whenever you have a template function, it needs to be in the header.
One thing that I like to do is use an inline file to keep things neat. Example:
Header:
1 2 3
void myFunc(void);
template<class T> T myTemplateFunc(T);
#include "myTemplates.inl"
myTemplates.inl: template<class T> T myTemplateFunc(T) { return T; }
@ The Ideas Man: Sorry about my formatting and thanks for your interest.
@Peter 87: Thank you so much for your reminder. My code now compiles and is undergoing testing.
@LowestOne and Stewbond: your argument is going a little bit over my head. With some slight alterations, my current course is working out nicely.
I'm having one final problem that I could use help with.
I am creating an application program, named dinorray_test.cpp, for my dynamic array class which simply uses the copy constructor:
#include <"dinorray.h"
using namespace std;
int main()
{
dinorray<char> dinosaur;
return 0;
}
When I compile this with the command "g++ dinorray.o dinorray_test.o -o dinorray_test", I end up with linking problems. Constructing the dinorray<char> produces an error message: undefined reference to 'dinorray<char> :: dinorray()' . I have a similar error message for the destructor.