I see multiple issues with your code, but most importantly, I don't get what are you trying to do.
Second most importantly: your use of
BASE<L>
and
BASE<L*>
looks very illegal.
My explanation why the compiler doesn't stop with an error immediately follows. I MAY be completely wrong, please correct me if so!
1 2
|
template <class L>
class BASE<L*>
|
Means (correct me if wrong!!!): "There is a template object, called BASE, which is defined, probably in some other file. Now, use the not yet known template input L, combine it to make the BASE<L*> object, and use it as an input to the class creation operation."
What does the compiler do when it sees
1 2
|
template <class L>
class BASE<L*>
|
?
It says: do I know what BASE is? It is not a regular object because it has template argument. Therefore BASE is a template, which has not been defined yet (perhaps it will be in some other file). I am therefore asked to do something with an unknown template. Now in view of the context I should crash, but the specifications specifically request that when I see an unknown template, I defer evaluation until the object is explicitly used.
This version of your code compiles and links, but I have no clue if it does what you want it to.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
template <class L>
class BASE;
class OBJECT
{
friend class BASE< OBJECT*>;//this is meant to be used by the initialization BASE<OBJECT> base_single_pointer;
private:
public:
OBJECT** COPY_OBJECT;
OBJECT(){}
~OBJECT(){}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <class L>
class BASE //the first class for double pointers; do I need <L*> here? No you don't!!!!
{
private:
L** BASE_OBJECT;//this is initialized on startup
public:
BASE();
~BASE();
void SET(L** data);
};
template <class L>
BASE<L>::BASE(){ this->BASE_OBJECT = new L*();}
template <class L>
BASE<L>::~BASE(){ delete (this->BASE_OBJECT);}
template <class L>
void BASE<L>::SET(L** NODE)
{
(this->BASE_OBJECT) = NODE;//this loads the object initialized BASE<OBJECT*> base_pointer;
(*this->BASE_OBJECT)->COPY_OBJECT = NODE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
BASE<OBJECT> base_pointer;//this tries to use the first BASE class for single pointers
OBJECT* theObjectPointer=new OBJECT;
OBJECT** theObjectPointerPointer=&theObjectPointer;
base_pointer.SET( theObjectPointerPointer );
//BASE<OBJECT*> base_double_pointer;//this tries to use the first BASE class for double pointers
//base_double_pointer.SET(new OBJECT*());
return 0;
}
|