POV-Ray : Newsgroups : povray.programming : Object oriented POV scene language? : Re: Object oriented POV scene language? Server Time
28 Jul 2024 16:32:11 EDT (-0400)
  Re: Object oriented POV scene language?  
From: Thorsten Froehlich
Date: 25 Jul 2000 06:33:52
Message: <397d6d10@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.