Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Use Assignment Operator On Both Types (http://www.velocityreviews.com/forums/t731620-use-assignment-operator-on-both-types.html)

Immortal Nephi 08-23-2010 11:27 PM

Use Assignment Operator On Both Types
 
I want to copy data from type 1 to another type 2. I insert Test_B’s
assignment operator function into Test_A’s class body. The C++
Compiler is able to compile successfully without errors.
If I move assignment operator function on the file scope outside
class body, C++ Compiler complains to report that this function is
unable to match another one and both of them look identical.

The error report shows here:

Compiling...
Test_MyCode.cpp
c:\ test_mycode.cpp(167) : error C2244:
'Test_A<nametype,traits_1>::operator =' : unable to match function
definition to an existing declaration
definition
'Test_A<nametype,traits_1>
&Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'
existing declarations
'Test_A<nametype,traits_1>
&Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'

You may discover that there are two template definitions in one
function. Look at assignment operator function.
Do you know how to fix that error?

enum NameTypes {
A_Type,
B_Type
};

template< NameTypes >
struct Traits_1 {
};

template<>
struct Traits_1< A_Type > {
static const unsigned char name_1;
static const unsigned char name_2;
};

template<>
struct Traits_1< B_Type > {
static const unsigned short name_1;
static const unsigned short name_2;
};


template< NameTypes >
struct Traits_2 {
};

template<>
struct Traits_2< A_Type > {
static const unsigned long data_1;
static const unsigned long data_2;
};

template<>
struct Traits_2< B_Type > {
static const unsigned long long data_1;
static const unsigned long long data_2;
};


template< NameTypes nametype, typename traits_2 >
class Test_B;


template< NameTypes nametype, typename traits_1 >
class Test_A {
public:
Test_A();
~Test_A();

void print();


template< NameTypes nametype, typename traits_2 >
Test_A& operator =( Test_B< nametype, traits_2 >& test_b ); /* {
this->x = test_b.x;
this->y = test_b.y;

this->u = traits_2::data_1;
this->v = traits_2::data_2;

cout << "u: " << hex << "0x" << +u << endl;
cout << "v: " << hex << "0x" << +v << endl;
cout << "x: " << hex << "0x" << +x << endl;
cout << "y: " << hex << "0x" << +y << endl;

return *this;
} */


unsigned long u;
unsigned long v;
unsigned long x;
unsigned long y;
};


template< NameTypes nametype, typename traits_2 >
class Test_B {
public:
Test_B();
~Test_B();

void print();

unsigned long x;
unsigned long y;
};



const unsigned char Traits_1< A_Type >::name_1 = 0x10;
const unsigned char Traits_1< A_Type >::name_2 = 0x23;

const unsigned short Traits_1< B_Type >::name_1 = 0x45;
const unsigned short Traits_1< B_Type >::name_2 = 0x7C;

const unsigned long Traits_2< A_Type >::data_1 = 0xFA;
const unsigned long Traits_2< A_Type >::data_2 = 0xEB;

const unsigned long long Traits_2< B_Type >::data_1 = 0x35;
const unsigned long long Traits_2< B_Type >::data_2 = 0x92;


template< NameTypes nametype, typename traits_1 >
Test_A< nametype, traits_1 >::Test_A() : u( 0 ), v( 0 ), x( 0 ),
y( 0 ) {
}

template< NameTypes nametype, typename traits_1 >
Test_A< nametype, traits_1 >::~Test_A() {
}

template< NameTypes nametype, typename traits_1 >
void Test_A< nametype, traits_1 >::print() {
cout << "name_1: " << hex << "0x" << +traits_1::name_1 << endl;
cout << "name_2: " << hex << "0x" << +traits_1::name_2 << endl;
}

// Notice two templates?
template< NameTypes nametype, typename traits_1 >
template< NameTypes nametype, typename traits_2 >
Test_A< nametype, traits_1 >&
Test_A< nametype, traits_1 >::
operator =( Test_B< nametype, traits_2 >& test_b ) {
this->x = test_b.x;
this->y = test_b.y;

this->u = traits_2::data_1;
this->v = traits_2::data_2;

cout << "u: " << hex << "0x" << +u << endl;
cout << "v: " << hex << "0x" << +v << endl;
cout << "x: " << hex << "0x" << +x << endl;
cout << "y: " << hex << "0x" << +y << endl;

return *this;
}


template< NameTypes nametype, typename traits_2 >
Test_B< nametype, traits_2 >::Test_B() : x( 0xFE ), y( 0xFC ) {
}

template< NameTypes nametype, typename traits_2 >
Test_B< nametype, traits_2 >::~Test_B() {
}

template< NameTypes nametype, typename traits_2 >
void Test_B< nametype, traits_2 >::print() {
cout << "name_1: " << hex << "0x" << +traits_2::data_1 << endl;
cout << "name_2: " << hex << "0x" << +traits_2::data_2 << endl;
}


int main() {
Test_A< A_Type, Traits_1< A_Type > > a;
Test_B< A_Type, Traits_2< A_Type > > b;

a.print();
b.print();

a = b;

return 0;
}

Pavel 08-24-2010 01:53 AM

Re: Use Assignment Operator On Both Types
 
Immortal Nephi wrote:
> I want to copy data from type 1 to another type 2. I insert Test_B’s
> assignment operator function into Test_A’s class body. The C++
> Compiler is able to compile successfully without errors.
> If I move assignment operator function on the file scope outside
> class body, C++ Compiler complains to report that this function is
> unable to match another one and both of them look identical.
>
> The error report shows here:
>
> Compiling...
> Test_MyCode.cpp
> c:\ test_mycode.cpp(167) : error C2244:
> 'Test_A<nametype,traits_1>::operator =' : unable to match function
> definition to an existing declaration
> definition
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'
> existing declarations
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'
>
> You may discover that there are two template definitions in one
> function. Look at assignment operator function.
> Do you know how to fix that error?
>
> enum NameTypes {
> A_Type,
> B_Type
> };
>
> template< NameTypes>
> struct Traits_1 {
> };
>
> template<>
> struct Traits_1< A_Type> {
> static const unsigned char name_1;
> static const unsigned char name_2;
> };
>
> template<>
> struct Traits_1< B_Type> {
> static const unsigned short name_1;
> static const unsigned short name_2;
> };
>
>
> template< NameTypes>
> struct Traits_2 {
> };
>
> template<>
> struct Traits_2< A_Type> {
> static const unsigned long data_1;
> static const unsigned long data_2;
> };
>
> template<>
> struct Traits_2< B_Type> {
> static const unsigned long long data_1;
> static const unsigned long long data_2;
> };
>
>
> template< NameTypes nametype, typename traits_2>
> class Test_B;
>
>
> template< NameTypes nametype, typename traits_1>
> class Test_A {
> public:
> Test_A();
> ~Test_A();
>
> void print();
>
>
> template< NameTypes nametype, typename traits_2>
> Test_A& operator =( Test_B< nametype, traits_2>& test_b ); /* {
> this->x = test_b.x;
> this->y = test_b.y;
>
> this->u = traits_2::data_1;
> this->v = traits_2::data_2;
>
> cout<< "u: "<< hex<< "0x"<< +u<< endl;
> cout<< "v: "<< hex<< "0x"<< +v<< endl;
> cout<< "x: "<< hex<< "0x"<< +x<< endl;
> cout<< "y: "<< hex<< "0x"<< +y<< endl;
>
> return *this;
> } */
>
>
> unsigned long u;
> unsigned long v;
> unsigned long x;
> unsigned long y;
> };
>
>
> template< NameTypes nametype, typename traits_2>
> class Test_B {
> public:
> Test_B();
> ~Test_B();
>
> void print();
>
> unsigned long x;
> unsigned long y;
> };
>
>
>
> const unsigned char Traits_1< A_Type>::name_1 = 0x10;
> const unsigned char Traits_1< A_Type>::name_2 = 0x23;
>
> const unsigned short Traits_1< B_Type>::name_1 = 0x45;
> const unsigned short Traits_1< B_Type>::name_2 = 0x7C;
>
> const unsigned long Traits_2< A_Type>::data_1 = 0xFA;
> const unsigned long Traits_2< A_Type>::data_2 = 0xEB;
>
> const unsigned long long Traits_2< B_Type>::data_1 = 0x35;
> const unsigned long long Traits_2< B_Type>::data_2 = 0x92;
>
>
> template< NameTypes nametype, typename traits_1>
> Test_A< nametype, traits_1>::Test_A() : u( 0 ), v( 0 ), x( 0 ),
> y( 0 ) {
> }
>
> template< NameTypes nametype, typename traits_1>
> Test_A< nametype, traits_1>::~Test_A() {
> }
>
> template< NameTypes nametype, typename traits_1>
> void Test_A< nametype, traits_1>::print() {
> cout<< "name_1: "<< hex<< "0x"<< +traits_1::name_1<< endl;
> cout<< "name_2: "<< hex<< "0x"<< +traits_1::name_2<< endl;
> }
>
> // Notice two templates?
> template< NameTypes nametype, typename traits_1>
> template< NameTypes nametype, typename traits_2>
> Test_A< nametype, traits_1>&
> Test_A< nametype, traits_1>::
> operator =( Test_B< nametype, traits_2>& test_b ) {
> this->x = test_b.x;
> this->y = test_b.y;
>
> this->u = traits_2::data_1;
> this->v = traits_2::data_2;
>
> cout<< "u: "<< hex<< "0x"<< +u<< endl;
> cout<< "v: "<< hex<< "0x"<< +v<< endl;
> cout<< "x: "<< hex<< "0x"<< +x<< endl;
> cout<< "y: "<< hex<< "0x"<< +y<< endl;
>
> return *this;
> }
>
>
> template< NameTypes nametype, typename traits_2>
> Test_B< nametype, traits_2>::Test_B() : x( 0xFE ), y( 0xFC ) {
> }
>
> template< NameTypes nametype, typename traits_2>
> Test_B< nametype, traits_2>::~Test_B() {
> }
>
> template< NameTypes nametype, typename traits_2>
> void Test_B< nametype, traits_2>::print() {
> cout<< "name_1: "<< hex<< "0x"<< +traits_2::data_1<< endl;
> cout<< "name_2: "<< hex<< "0x"<< +traits_2::data_2<< endl;
> }
>
>
> int main() {
> Test_A< A_Type, Traits_1< A_Type> > a;
> Test_B< A_Type, Traits_2< A_Type> > b;
>
> a.print();
> b.print();
>
> a = b;
>
> return 0;
> }

You need to rename one of your 'nametype' template parameters to
something else.

Hope this will help,
-Pavel

Immortal Nephi 08-24-2010 03:05 AM

Re: Use Assignment Operator On Both Types
 
On Aug 23, 8:53*pm, Pavel
<pauldontspamt...@removeyourself.dontspam.yahoo> wrote:
> Immortal Nephi wrote:
> > * *I want to copy data from type 1 to another type 2. *I insert Test_B’s
> > assignment operator function into Test_A’s class body. *The C++
> > Compiler is able to compile successfully without errors.
> > * *If I move assignment operator function on the file scope outside
> > class body, C++ Compiler complains to report that this function is
> > unable to match another one and both of them look identical.

>
> > * *The error report shows here:

>
> > Compiling...
> > Test_MyCode.cpp
> > c:\ test_mycode.cpp(167) : error C2244:
> > 'Test_A<nametype,traits_1>::operator =' : unable to match function
> > definition to an existing declaration
> > * * * * *definition
> > * * * * *'Test_A<nametype,traits_1>
> > &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> *&)'
> > * * * * *existing declarations
> > * * * * *'Test_A<nametype,traits_1>
> > &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> *&)'

>
> > * *You may discover that there are two template definitions in one
> > function. *Look at assignment operator function.
> > * *Do you know how to fix that error?

>
> > enum NameTypes {
> > * *A_Type,
> > * *B_Type
> > };

>
> > template< *NameTypes>
> > struct Traits_1 {
> > };

>
> > template<>
> > struct Traits_1< *A_Type> *{
> > * *static const unsigned char name_1;
> > * *static const unsigned char name_2;
> > };

>
> > template<>
> > struct Traits_1< *B_Type> *{
> > * *static const unsigned short name_1;
> > * *static const unsigned short name_2;
> > };

>
> > template< *NameTypes>
> > struct Traits_2 {
> > };

>
> > template<>
> > struct Traits_2< *A_Type> *{
> > * *static const unsigned long data_1;
> > * *static const unsigned long data_2;
> > };

>
> > template<>
> > struct Traits_2< *B_Type> *{
> > * *static const unsigned long long data_1;
> > * *static const unsigned long long data_2;
> > };

>
> > template< *NameTypes nametype, typename traits_2>
> > class Test_B;

>
> > template< *NameTypes nametype, typename traits_1>
> > class Test_A {
> > public:
> > * *Test_A();
> > * *~Test_A();

>
> > * *void print();

>
> > * *template< *NameTypes nametype, typename traits_2>
> > * *Test_A& *operator =( Test_B< *nametype, traits_2>& *test_b ); /* {
> > * * * * * *this->x = test_b.x;
> > * * * * * *this->y = test_b.y;

>
> > * * * * * *this->u = traits_2::data_1;
> > * * * * * *this->v = traits_2::data_2;

>
> > * * * * * *cout<< *"u: "<< *hex<< *"0x"<< *+u<< *endl;
> > * * * * * *cout<< *"v: "<< *hex<< *"0x"<< *+v<< *endl;
> > * * * * * *cout<< *"x: "<< *hex<< *"0x"<< *+x<< *endl;
> > * * * * * *cout<< *"y: "<< *hex<< *"0x"<< *+y<< *endl;

>
> > * * * * * *return *this;
> > * *} */

>
> > * *unsigned long u;
> > * *unsigned long v;
> > * *unsigned long x;
> > * *unsigned long y;
> > };

>
> > template< *NameTypes nametype, typename traits_2>
> > class Test_B {
> > public:
> > * *Test_B();
> > * *~Test_B();

>
> > * *void print();

>
> > * *unsigned long x;
> > * *unsigned long y;
> > };

>
> > const unsigned char Traits_1< *A_Type>::name_1 = 0x10;
> > const unsigned char Traits_1< *A_Type>::name_2 = 0x23;

>
> > const unsigned short Traits_1< *B_Type>::name_1 = 0x45;
> > const unsigned short Traits_1< *B_Type>::name_2 = 0x7C;

>
> > const unsigned long Traits_2< *A_Type>::data_1 = 0xFA;
> > const unsigned long Traits_2< *A_Type>::data_2 = 0xEB;

>
> > const unsigned long long Traits_2< *B_Type>::data_1 = 0x35;
> > const unsigned long long Traits_2< *B_Type>::data_2 = 0x92;

>
> > template< *NameTypes nametype, typename traits_1>
> > Test_A< *nametype, traits_1>::Test_A() : u( 0 ), v( 0 ), x( 0 ),
> > y( 0 ) {
> > }

>
> > template< *NameTypes nametype, typename traits_1>
> > Test_A< *nametype, traits_1>::~Test_A() {
> > }

>
> > template< *NameTypes nametype, typename traits_1>
> > void Test_A< *nametype, traits_1>::print() {
> > * *cout<< *"name_1: "<< *hex<< *"0x"<< *+traits_1::name_1<< *endl;
> > * *cout<< *"name_2: "<< *hex<< *"0x"<< *+traits_1::name_2<< *endl;
> > }

>
> > // Notice two templates?
> > template< *NameTypes nametype, typename traits_1>
> > template< *NameTypes nametype, typename traits_2>
> > Test_A< *nametype, traits_1>&
> > Test_A< *nametype, traits_1>::
> > operator =( Test_B< *nametype, traits_2>& *test_b ) {
> > * *this->x = test_b.x;
> > * *this->y = test_b.y;

>
> > * *this->u = traits_2::data_1;
> > * *this->v = traits_2::data_2;

>
> > * *cout<< *"u: "<< *hex<< *"0x"<< *+u<< *endl;
> > * *cout<< *"v: "<< *hex<< *"0x"<< *+v<< *endl;
> > * *cout<< *"x: "<< *hex<< *"0x"<< *+x<< *endl;
> > * *cout<< *"y: "<< *hex<< *"0x"<< *+y<< *endl;

>
> > * *return *this;
> > }

>
> > template< *NameTypes nametype, typename traits_2>
> > Test_B< *nametype, traits_2>::Test_B() : x( 0xFE ), y( 0xFC ) {
> > }

>
> > template< *NameTypes nametype, typename traits_2>
> > Test_B< *nametype, traits_2>::~Test_B() {
> > }

>
> > template< *NameTypes nametype, typename traits_2>
> > void Test_B< *nametype, traits_2>::print() {
> > * *cout<< *"name_1: "<< *hex<< *"0x"<< *+traits_2::data_1<< *endl;
> > * *cout<< *"name_2: "<< *hex<< *"0x"<< *+traits_2::data_2<< *endl;
> > }

>
> > int main() {
> > * *Test_A< *A_Type, Traits_1< *A_Type> *> *a;
> > * *Test_B< *A_Type, Traits_2< *A_Type> *> *b;

>
> > * *a.print();
> > * *b.print();

>
> > * *a = b;

>
> > * *return 0;
> > }

>
> You need to rename one of your 'nametype' template parameters to
> something else.
>
> Hope this will help,
> -Pavel- Hide quoted text -
>
> - Show quoted text -


You did not explain very clear how you say rename ‘nametype’. I
think you are referring two separate enum types? One ‘NameTypes’ is
for Test_A class and another ‘NameTypes2’ is for Test_B.
Is it what you mean? Will C++ Compiler be able to compile if there
are two enum types.

tni 08-24-2010 06:20 AM

Re: Use Assignment Operator On Both Types
 
On 2010-08-24 1:27, Immortal Nephi wrote:
> I want to copy data from type 1 to another type 2. I insert Test_B’s
> assignment operator function into Test_A’s class body. The C++
> Compiler is able to compile successfully without errors.
> If I move assignment operator function on the file scope outside
> class body, C++ Compiler complains to report that this function is
> unable to match another one and both of them look identical.
>
> The error report shows here:
>
> Compiling...
> Test_MyCode.cpp
> c:\ test_mycode.cpp(167) : error C2244:
> 'Test_A<nametype,traits_1>::operator =' : unable to match function
> definition to an existing declaration
> definition
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'
> existing declarations
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'
>
>
> [...]
> // Notice two templates?
> template< NameTypes nametype, typename traits_1>
> template< NameTypes nametype, typename traits_2>
> Test_A< nametype, traits_1>&
> Test_A< nametype, traits_1>::
> operator =( Test_B< nametype, traits_2>& test_b ) {
> [...]


You want unique template parameters, e.g.:

template< NameTypes nametype1, typename traits_1 >
template< NameTypes nametype2, typename traits_2 >
Test_A< nametype1, traits_1 >&
Test_A< nametype1, traits_1 >::
operator =( Test_B< nametype2, traits_2 >& test_b ) {


Pavel 08-28-2010 10:32 PM

Re: Use Assignment Operator On Both Types
 
Immortal Nephi wrote:
> On Aug 23, 8:53 pm, Pavel
> <pauldontspamt...@removeyourself.dontspam.yahoo> wrote:
>> Immortal Nephi wrote:
>>> I want to copy data from type 1 to another type 2. I insert Test_B’s
>>> assignment operator function into Test_A’s class body. The C++
>>> Compiler is able to compile successfully without errors.
>>> If I move assignment operator function on the file scope outside
>>> class body, C++ Compiler complains to report that this function is
>>> unable to match another one and both of them look identical.

>>
>>> The error report shows here:

>>
>>> Compiling...
>>> Test_MyCode.cpp
>>> c:\ test_mycode.cpp(167) : error C2244:
>>> 'Test_A<nametype,traits_1>::operator =' : unable to match function
>>> definition to an existing declaration
>>> definition
>>> 'Test_A<nametype,traits_1>
>>> &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'
>>> existing declarations
>>> 'Test_A<nametype,traits_1>
>>> &Test_A<nametype,traits_1>::operator =(Test_B<nametype,traits_2> &)'

>>
>>> You may discover that there are two template definitions in one
>>> function. Look at assignment operator function.
>>> Do you know how to fix that error?

>>
>>> enum NameTypes {
>>> A_Type,
>>> B_Type
>>> };

>>
>>> template< NameTypes>
>>> struct Traits_1 {
>>> };

>>
>>> template<>
>>> struct Traits_1< A_Type> {
>>> static const unsigned char name_1;
>>> static const unsigned char name_2;
>>> };

>>
>>> template<>
>>> struct Traits_1< B_Type> {
>>> static const unsigned short name_1;
>>> static const unsigned short name_2;
>>> };

>>
>>> template< NameTypes>
>>> struct Traits_2 {
>>> };

>>
>>> template<>
>>> struct Traits_2< A_Type> {
>>> static const unsigned long data_1;
>>> static const unsigned long data_2;
>>> };

>>
>>> template<>
>>> struct Traits_2< B_Type> {
>>> static const unsigned long long data_1;
>>> static const unsigned long long data_2;
>>> };

>>
>>> template< NameTypes nametype, typename traits_2>
>>> class Test_B;

>>
>>> template< NameTypes nametype, typename traits_1>
>>> class Test_A {
>>> public:
>>> Test_A();
>>> ~Test_A();

>>
>>> void print();

>>
>>> template< NameTypes nametype, typename traits_2>
>>> Test_A& operator =( Test_B< nametype, traits_2>& test_b ); /* {
>>> this->x = test_b.x;
>>> this->y = test_b.y;

>>
>>> this->u = traits_2::data_1;
>>> this->v = traits_2::data_2;

>>
>>> cout<< "u: "<< hex<< "0x"<< +u<< endl;
>>> cout<< "v: "<< hex<< "0x"<< +v<< endl;
>>> cout<< "x: "<< hex<< "0x"<< +x<< endl;
>>> cout<< "y: "<< hex<< "0x"<< +y<< endl;

>>
>>> return *this;
>>> } */

>>
>>> unsigned long u;
>>> unsigned long v;
>>> unsigned long x;
>>> unsigned long y;
>>> };

>>
>>> template< NameTypes nametype, typename traits_2>
>>> class Test_B {
>>> public:
>>> Test_B();
>>> ~Test_B();

>>
>>> void print();

>>
>>> unsigned long x;
>>> unsigned long y;
>>> };

>>
>>> const unsigned char Traits_1< A_Type>::name_1 = 0x10;
>>> const unsigned char Traits_1< A_Type>::name_2 = 0x23;

>>
>>> const unsigned short Traits_1< B_Type>::name_1 = 0x45;
>>> const unsigned short Traits_1< B_Type>::name_2 = 0x7C;

>>
>>> const unsigned long Traits_2< A_Type>::data_1 = 0xFA;
>>> const unsigned long Traits_2< A_Type>::data_2 = 0xEB;

>>
>>> const unsigned long long Traits_2< B_Type>::data_1 = 0x35;
>>> const unsigned long long Traits_2< B_Type>::data_2 = 0x92;

>>
>>> template< NameTypes nametype, typename traits_1>
>>> Test_A< nametype, traits_1>::Test_A() : u( 0 ), v( 0 ), x( 0 ),
>>> y( 0 ) {
>>> }

>>
>>> template< NameTypes nametype, typename traits_1>
>>> Test_A< nametype, traits_1>::~Test_A() {
>>> }

>>
>>> template< NameTypes nametype, typename traits_1>
>>> void Test_A< nametype, traits_1>::print() {
>>> cout<< "name_1: "<< hex<< "0x"<< +traits_1::name_1<< endl;
>>> cout<< "name_2: "<< hex<< "0x"<< +traits_1::name_2<< endl;
>>> }

>>
>>> // Notice two templates?
>>> template< NameTypes nametype, typename traits_1>
>>> template< NameTypes nametype, typename traits_2>
>>> Test_A< nametype, traits_1>&
>>> Test_A< nametype, traits_1>::
>>> operator =( Test_B< nametype, traits_2>& test_b ) {
>>> this->x = test_b.x;
>>> this->y = test_b.y;

>>
>>> this->u = traits_2::data_1;
>>> this->v = traits_2::data_2;

>>
>>> cout<< "u: "<< hex<< "0x"<< +u<< endl;
>>> cout<< "v: "<< hex<< "0x"<< +v<< endl;
>>> cout<< "x: "<< hex<< "0x"<< +x<< endl;
>>> cout<< "y: "<< hex<< "0x"<< +y<< endl;

>>
>>> return *this;
>>> }

>>
>>> template< NameTypes nametype, typename traits_2>
>>> Test_B< nametype, traits_2>::Test_B() : x( 0xFE ), y( 0xFC ) {
>>> }

>>
>>> template< NameTypes nametype, typename traits_2>
>>> Test_B< nametype, traits_2>::~Test_B() {
>>> }

>>
>>> template< NameTypes nametype, typename traits_2>
>>> void Test_B< nametype, traits_2>::print() {
>>> cout<< "name_1: "<< hex<< "0x"<< +traits_2::data_1<< endl;
>>> cout<< "name_2: "<< hex<< "0x"<< +traits_2::data_2<< endl;
>>> }

>>
>>> int main() {
>>> Test_A< A_Type, Traits_1< A_Type> > a;
>>> Test_B< A_Type, Traits_2< A_Type> > b;

>>
>>> a.print();
>>> b.print();

>>
>>> a = b;

>>
>>> return 0;
>>> }

>>
>> You need to rename one of your 'nametype' template parameters to
>> something else.
>>
>> Hope this will help,
>> -Pavel- Hide quoted text -
>>
>> - Show quoted text -

>
> You did not explain very clear how you say rename ‘nametype’. I
> think you are referring two separate enum types? One ‘NameTypes’ is
> for Test_A class and another ‘NameTypes2’ is for Test_B.
> Is it what you mean? Will C++ Compiler be able to compile if there
> are two enum types.

Yes. (as in the example of tni). g++ error message actually gives a
clue. So another little common-wisdom advice is to try another compiler
if one gives a not-too-useful error message (just for this purpose; I am
not saying one is better than another in general; but two are sometimes
better than one).

-Pavel


All times are GMT. The time now is 05:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.