Archived

This topic is now archived and is closed to further replies.

Templates will be the end of me

This topic is 5009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites