PDA

View Full Version : seek c++ programmer



jide
09-10-2001, 12:00 AM
Does someone has knowledge with templates ?

nickels
09-28-2001, 01:41 PM
yes. http://www.opengl.org/discussion_boards/ubb/smile.gif

mikael_aronsson
10-01-2001, 03:41 AM
Do a quick search on google or any other search engine, there are lots of info about it there.

Mikael

jide
10-02-2001, 09:54 PM
Originally posted by nickels:
yes. http://www.opengl.org/discussion_boards/ubb/smile.gif

hello, i've send you an email, but you seem not having replied.

nickels
10-10-2001, 06:45 AM
I was just trying to be a funny guy (smart-aleck).

I do know a lot about templates and can offer answers, but I don't have time to jump aboard your project. Too busy climbing rocks and mountains! http://www.opengl.org/discussion_boards/ubb/smile.gif

jide
10-21-2001, 03:18 AM
hello.

OK. you don't need to climb my project. i only wanted to know why my templates are not working as i want.

witcomb
10-21-2001, 01:36 PM
Well, you may have to be a little more descriptive. I know that I myself am not telepathic so I can't help much at the moment.

Neil

jide
10-29-2001, 02:09 AM
sorry for the late, but i haven't got the net at home.

I wanted to make generic template classes to avoid redundant implementation of linked list functionalities. My classes are hierarchic, from one mother class. I use polymorphism.

my template implementation is something like this:

template <class O> class list_object
{
O *next;
O *prev;

list_object( ...)
};

template <class O> class list: public list_object
{
// i don't remember here
void AddObject( O data);
void RemoveObject( O data);
};

All seems OK: compilation, linking ( i had errors while linking before, but i correct it). But while executing everything's going bad and worst !

maybe you'll need to see the code ?

nickels
10-29-2001, 01:03 PM
Try:

template <class O> class list: public list_object<O>
{
void AddObject( O data);
void RemoveObject( O data);
}

list_object needs to have the template parameter specified.

DN

jide
10-31-2001, 01:45 AM
first, thanks for your care.
(sorry if my english not very good)
But, that's not made any good change.
now, i have to implement the template methods
inner the class definition. that's a wrap !
Now it seems it couldn't create these objects, it seems it overwrite other memory emplacements.
I may go forward each time i try again, but i think i will never succeed.

I would like to know: templates seem to not work if there are preprocessor declaration inner the class. But if the preprocessor declaration is inner the class to match, is it not good too ?
thanks

jide
11-02-2001, 03:57 AM
Originally posted by jide:
first, thanks for your care.
(sorry if my english not very good)
But, that's not made any good change.
now, i have to implement the template methods
inner the class definition. that's a wrap !
Now it seems it couldn't create these objects, it seems it overwrite other memory emplacements.
I may go forward each time i try again, but i think i will never succeed.

I would like to know: templates seem to not work if there are preprocessor declaration inner the class. But if the preprocessor declaration is inner the class to match, is it not good too ?
thanks

jide
11-02-2001, 03:58 AM
I have succeed the day before yesterday !
But i must let all my methods implementation in the class definition (*.h).
I don't know why !

nickels
11-02-2001, 12:04 PM
Yes, the code all has to go in the .h for templates. This is because without knowing what the template parameter type is the compiler can not generate code. Thus a .o file can not be created until you actually include the code into some other code that is using a specific type.

DN

jide
11-05-2001, 12:24 AM
Do you know any other manner to do that and not to put all the code in the header files ?
Otherwise, thanks for all.
Jidé

nickels
11-05-2001, 06:48 AM
Some compilers (SunOs, SGI) have 'smart template' compilation, but my experience has been that it causes more headaches than it solves and I usually end up turning that functionallity off.

I have seen people create the following:

/* File myclass.h */

template<class T> class myclass
{
public:
T some_functions();
};

#include "myclass.i

EOF

/* File myclass.i */

template<class T>
T myclass<T>::some_functions()
{
}


****************************************

This works kind of like having a .h and .C file, it is more organized. However, the compiler still has to parse the whole file every time it uses this....

DN