Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Use Assignment Operator On Both Types

Reply
Thread Tools

Use Assignment Operator On Both Types

 
 
Immortal Nephi
Guest
Posts: n/a
 
      08-23-2010
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>:perator =' : unable to match function
definition to an existing declaration
definition
'Test_A<nametype,traits_1>
&Test_A<nametype,traits_1>:perator =(Test_B<nametype,traits_2> &)'
existing declarations
'Test_A<nametype,traits_1>
&Test_A<nametype,traits_1>:perator =(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 >:rint() {
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 >:rint() {
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;
}
 
Reply With Quote
 
 
 
 
Pavel
Guest
Posts: n/a
 
      08-24-2010
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>:perator =' : unable to match function
> definition to an existing declaration
> definition
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>:perator =(Test_B<nametype,traits_2> &)'
> existing declarations
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>:perator =(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>:rint() {
> 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>:rint() {
> 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
 
Reply With Quote
 
 
 
 
Immortal Nephi
Guest
Posts: n/a
 
      08-24-2010
On Aug 23, 8:53*pm, Pavel
<(E-Mail Removed)> 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>:perator =' : unable to match function
> > definition to an existing declaration
> > * * * * *definition
> > * * * * *'Test_A<nametype,traits_1>
> > &Test_A<nametype,traits_1>:perator =(Test_B<nametype,traits_2> *&)'
> > * * * * *existing declarations
> > * * * * *'Test_A<nametype,traits_1>
> > &Test_A<nametype,traits_1>:perator =(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>:rint() {
> > * *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>:rint() {
> > * *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.
 
Reply With Quote
 
tni
Guest
Posts: n/a
 
      08-24-2010
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>:perator =' : unable to match function
> definition to an existing declaration
> definition
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>:perator =(Test_B<nametype,traits_2> &)'
> existing declarations
> 'Test_A<nametype,traits_1>
> &Test_A<nametype,traits_1>:perator =(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 ) {

 
Reply With Quote
 
Pavel
Guest
Posts: n/a
 
      08-28-2010
Immortal Nephi wrote:
> On Aug 23, 8:53 pm, Pavel
> <(E-Mail Removed)> 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>:perator =' : unable to match function
>>> definition to an existing declaration
>>> definition
>>> 'Test_A<nametype,traits_1>
>>> &Test_A<nametype,traits_1>:perator =(Test_B<nametype,traits_2> &)'
>>> existing declarations
>>> 'Test_A<nametype,traits_1>
>>> &Test_A<nametype,traits_1>:perator =(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>:rint() {
>>> 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>:rint() {
>>> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
POD and assignment operator and test operator Hicham Mouline C++ 2 09-01-2009 06:00 PM
conditions for automatic generation of default ctor, copy ctor,and default assignment operator (operator) puzzlecracker C++ 8 04-15-2008 09:56 PM
Assignment operator self-assignment check Chris C++ 34 09-26-2006 04:26 AM
2 computers, both online, both invisible to each other ? b Computer Support 9 04-21-2006 04:06 AM
comma operator and assignment operator G Patel C Programming 4 02-08-2005 02:53 AM



Advertisments