Templates will be the end of me

Started by
6 comments, last by Ataru 20 years, 1 month ago
Why does this not compile? I have some very similar code elsewhere, and it compiles. I just cannot figure it out.

#include <vector>
using namespace std;

#include "GEOMETRY.h"
#include "SCREEN_ALIGNED_QUAD.H"

template <class T> class PARTICLE_SYSTEM : public GEOMETRY  
{
public:

	PARTICLE_SYSTEM();
	virtual ~PARTICLE_SYSTEM()
	{
		vector<T>::iterator p;
		p = pList.begin();
		while (p != pList.end())
		{
			p++;
		}
	}
        vector<T> pList;
}
I get the following error at p++ "error C2036: 'class T *' : unknown size" of course it's unknown size, that's what templates are for!!?!? I'm getting a little frustrated, I have, what seems like identical code in another project, and it compiles fine. What on earth is wrong here. I can of course make pList declared as vector pList. I can itterate through T. But i cannot do something like delete (*p)->particleObject; Because it complains that I am using an undefined type. When I initialzie the particle system, I give a type, so I'm not sure why the compiler is complaning. [edited by - ataru on March 25, 2004 1:51:40 PM]
Advertisement
Ataru,

You didn''t define your constructor. If its still giving you problems, you should post the source for the GEOMETRY class also.

-brad
-brad
Found the problem. I did define the constructor, in the cpp. That was the problem, when I moved all the definitions into the .h everything compiled.

I have learned once again, do not try to use a cpp file with templates.
Indeed, never do. I inevitably forget this when working with templates and inevitably screw up every time too. Maybe MS should fix their damn compiler.
Thank god I''m not the only one. This has bitten me several times before. Maybe it''s my "no fear" mentality. Like I believe I can actually compile it that way, so I force myself to forget.

Hopefully it''s the last time.
quote:Original post by psamty10
Indeed, never do. I inevitably forget this when working with templates and inevitably screw up every time too. Maybe MS should fix their damn compiler.

So should GCC.
And Digital Mars.
And Intel.
And Borland.
And Metrowerks.

Ad nauseum, minus Comeau with a command line switch.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
quote:Original post by psamty10
Indeed, never do. I inevitably forget this when working with templates and inevitably screw up every time too. Maybe MS should fix their damn compiler.

Hmm, maybe... if you''d been following the discussion some years ago on implementing export you might''ve known that separate compilation for templates is not a two day fix, more like three man-years or something (according to EDG the only ones who has done it). Read this and this to get a better view of the actual problem and why it might not even be so desirable to have after all. Then go to google-groups comp.lang.c++.* and search for "export" to read some more...
No, templates will not be the end of you, we won't let that happen you son of a bitch! Oh... problem already solved. Carry on.

.inl files or inline implementation aren't that bad anyway.

[edited by - Chris Hare on March 25, 2004 5:41:23 PM]

This topic is closed to new replies.

Advertisement