Seek c++ programmer

Does someone has knowledge with templates ?

yes.

Do a quick search on google or any other search engine, there are lots of info about it there.

Mikael

Originally posted by nickels:
yes.

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

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!

hello.

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

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

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 ?

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

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

Originally posted by jide:
[b]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[/b]

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 !

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

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é

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

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.