I want to implement a class of dynamic array in c++, and I want this implementation to be generic.
Consider the following definition:
ef DYNAMICARRAY_H
#define DYNAMICARRAY_H
template<class T>
class DynamicArray
{
public:
DynamicArray();
virtual ~DynamicArray();
protected:
private:
};
#endif // DYNAMICARRAY_H
(I did not wrote any methods yet).
Usually, we implement the methods in another cpp file. But since it is a generic class, we'll have problem with the linker after compilation with methods that use the generic types.
On the other hand, as I understand, implementing such a function in the header file might cause the compiler to make the function an inline function.
So what would be the best way to implement such functions? should it be inside the class definition? (case1) should it be in outside the class definition but inside the header file? (case2)
#ifndef DYNAMICARRAY_H
#define DYNAMICARRAY_H
template<class T>
class DynamicArray
{
public:
DynamicArray();
virtual ~DynamicArray();
protected:
private:
//Should I implement here right after decleration? (case 1)
};
//Or should I implement here outside of the class definition? (case2)
#endif // DYNAMICARRAY_H
Or maybe in the cpp file and to include the line:
#include "DynamicArray.cpp"
above the main function?
Thanks in advance.