PDA

Click to See Complete Forum and Search --> : Container


made_of_asp
Oct 12th, 2002, 03:50 AM
Hi :)

I am trying to develop a management class and store any type of class within. I think its possible using interfaces.

Is that possible to do without templates? :confused:

parksie
Oct 12th, 2002, 03:54 AM
Without templates? Why not? If you really can't use them, then you can use polymorphism and have all the objects you store in it deriving from a single class, then storing pointers.

made_of_asp
Oct 12th, 2002, 03:55 AM
I can use templates, but i don't know how :(

parksie
Oct 12th, 2002, 04:08 AM
www.bruceeckel.com -- Thinking in C++. I think it's Volume 2 that goes into templates...

made_of_asp
Oct 12th, 2002, 04:12 AM
Thanks for your reply :)

I already have abook on templates in C++... but i dont understand them


Can you tell me whats wrong with this?


template <class T>
class CObjectStorage
{
public:
void Alloc(int);
private:
T* stor;

};

template <class T>
void CObjectStorage<T>::Alloc(int size)
{
//using
};

kedaman
Oct 12th, 2002, 05:56 AM
compiles fine for me, maybe you're using a compiler that doesn't support templates well? templates are used for polymorphism but without the overheads, and are all set during compiletime

made_of_asp
Oct 12th, 2002, 08:32 AM
I am using MSVC 6.0

It compiles but doesnt link when i try to actually use it:

CObjectStorage<int> a;
a.Alloc(10);

above ^^^^ doesnt work... (

CornedBee
Oct 12th, 2002, 08:34 AM
What linker error?

made_of_asp
Oct 12th, 2002, 09:12 PM
This comes up:


--------------------Configuration: Interfacing - Win32 Debug--------------------
Linking...
Interfacing.obj : error LNK2001: unresolved external symbol "public: void __thiscall CObjectStorage<int>::Alloc(long)" (?Alloc@?$CObjectStorage@H@@QAEXJ@Z)
Debug/Interfacing.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Interfacing.exe - 2 error(s), 0 warning(s)

Zaei
Oct 12th, 2002, 10:44 PM
Are the actual member functions in a separate .cpp? If that is the case, paste them into the header, and remove the .cpp from the project, and try it again.

Z.