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:
Printable View
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:
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.
I can use templates, but i don't know how :(
www.bruceeckel.com -- Thinking in C++. I think it's Volume 2 that goes into templates...
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?
PHP Code:template <class T>
class CObjectStorage
{
public:
void Alloc(int);
private:
T* stor;
};
template <class T>
void CObjectStorage<T>::Alloc(int size)
{
//using
};
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
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... (
What linker error?
This comes up:
Quote:
--------------------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)
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.