POV-Ray : Newsgroups : povray.programming : Object oriented POV scene language? : Re: Object oriented POV scene language? Server Time
28 Jul 2024 16:24:39 EDT (-0400)
  Re: Object oriented POV scene language?  
From: Thorsten Froehlich
Date: 24 Jul 2000 11:27:20
Message: <397c6058@news.povray.org>
In article <397c5123@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

>  Are you sure? How do you make this extremely simple template in C:
>
> template<typename T>
> void swap(T& x, T& y)
> {
>   T tmp = x;
>   x = y;
>   y = tmp;
> }

I would do it with include files that are not protected from
multiple-inclusion.  It could look like this:

FILE: mytmpl.h

void TEMPLATE_swap(T& x, T& y);

void TEMPLATE_swap(TEMPLATE_T& x, TEMPLATE_T& y)
// OK, there are no references in C...
{
  TEMPLATE_T tmp = x;
  x = y;
  y = tmp;
}


FILE: mymain.c

#define T int
#define TEMPLATE_swap swap1
#include "mytmpl.h"
#undef TEMPLATE_swap
#undef T

#define T char *
#define TEMPLATE_swap swap2
#include "mytmpl.h"
#undef TEMPLATE_swap
#undef T


While this is more work than just two functions, it does exactly the same.

However, if you have complex "classes" (structs) you only have to create a
new class name but can reuse the code without having to rename each
function.


     Thorsten


____________________________________________________
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.