|
|
In article <397d59ed@news.povray.org> , Warp <war### [at] tagpovrayorg> wrote:
> Ok, let's take this a step further:
OK, keep in mind that I pointed out before "The only thing really missing is
operator overloading...". So a trick is needed to replace your overloaded
operator. Of course this trick won't work with built-in types and two
versions of your template will be needed, one for classes and one for
built-in types!
FILE: mytmpl.h
void TEMPLATE_swap(T1& x, T2& y);
void TEMPLATE_swap(TEMPLATE_T1& x, TEMPLATE_T2& y)
// OK, there are no references in C...
{
TEMPLATE_T1 tmp = x; // may need "copy" constructor replacement here
x.assignment(&x, y);
y.assignment(&y, tmp);
}
FILE: mymain.c
// First, every "class" gets "assignment" member functions:
struct A
{
void (*assignment)(A *this, B& b);
};
struct B
{
void (*assignment)(B *this, A& a);
};
#define T1 A
#define T2 B
#define TEMPLATE_swap swap_AB
#include "mytmpl.h"
#undef T1
#undef T2
int main(void)
{
A a;
B b;
swap_AB(a,b);
return 0;
}
____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde
Visit POV-Ray on the web: http://mac.povray.org
Post a reply to this message
|
|