N
none
I'm trying to overload the = operator using templates, but I have
some problems with one of the overloads, I would like to make
something like that:
intvariable = fooclass;
here's a pseudo code of what I'm doing:
template <class COMPLEXTYPE>
class foo
{
public:
COMPLEXTYPE data;
foo (void) { }
~foo (void) { }
foo<COMPLEXTYPE> operator = (foo<COMPLEXTYPE> source);
{
this->data = source.data;
return *this;
}
foo<COMPLEXTYPE> operator = (COMPLEXTYPE source);
{
this->data = source;
return *this;
}
}
// THIS IS THE SECTION THAT I'M NOT ABLE TO GET WORKING
// of unknown class
template <COMPLEXTYPE>
COMPLEXTYPE operator = (COMPLEXTYPE dest, foo<COMPLEXTYPE> source)
{
dest = (COMPLEXTYPE) source.data;
return dest;
}
main (void)
{
foo<int> FOOINT;
foo<int> FOOINT2;
int integer;
FOOTINT.data = 1;
integer = 4;
FOOINT2 = FOOINT; // works
FOOINT = integer; // works
integer = FOOINT2; // does not work
}
Anyone knows what's wrong? I know we can't overload
the basic operators but I thought I could do something
like that. Thanks in advance
some problems with one of the overloads, I would like to make
something like that:
intvariable = fooclass;
here's a pseudo code of what I'm doing:
template <class COMPLEXTYPE>
class foo
{
public:
COMPLEXTYPE data;
foo (void) { }
~foo (void) { }
foo<COMPLEXTYPE> operator = (foo<COMPLEXTYPE> source);
{
this->data = source.data;
return *this;
}
foo<COMPLEXTYPE> operator = (COMPLEXTYPE source);
{
this->data = source;
return *this;
}
}
// THIS IS THE SECTION THAT I'M NOT ABLE TO GET WORKING
// of unknown class
template <COMPLEXTYPE>
COMPLEXTYPE operator = (COMPLEXTYPE dest, foo<COMPLEXTYPE> source)
{
dest = (COMPLEXTYPE) source.data;
return dest;
}
main (void)
{
foo<int> FOOINT;
foo<int> FOOINT2;
int integer;
FOOTINT.data = 1;
integer = 4;
FOOINT2 = FOOINT; // works
FOOINT = integer; // works
integer = FOOINT2; // does not work
}
Anyone knows what's wrong? I know we can't overload
the basic operators but I thought I could do something
like that. Thanks in advance