Archived

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

templated class g++ problem

This topic is 5173 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

Ok, so I have this code from my prof, actually the prof who taught the class before my current prof. Its a templated vector class so the header file contains the declarations. Then the .cpp file contains all the definitions and the .cpp file included in the header file. However I can''t seem to get them to compile because g++ won''t compile a header file and thats basically what needs to happen. Any ideas about how to fix this. I usually use VC++ but all the assignments need to be done on unix because thats the way they check everything. Any help would be appreciated.

Share this post


Link to post
Share on other sites
You can force GCC to treat it as a source file (use -x c++). You should only need to be compiling files that actually have something to compile (a templated class leads to no code until it''s used), so I don''t see why you''d want to do this. What''s wrong with just including the header in another source file and using it when building that source file without "compiling the header"?

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
You don''t put template implementations in .cpp files, they have to be in the .hpp.

He mentions that:
quote:
doodah2001
Then the .cpp file contains all the definitions and the .cpp file included in the header file.

Which is an idiom that I''m sure you''re aware of. Still, I don''t see why he wants or thinks he needs to "compile" a header file.

Share this post


Link to post
Share on other sites
The problem has been fixed. Apparently there was a bug within the header that had to be taken care of. Just to let you know, I was trying to compile the main program, which was in main.cpp. I know you can''t compile a templated class because there is no real instantiation of the class until its used which it was first used in main.cpp. The header file did have a problem which caused this error though. I guess the moral of the story is not to trust anyone elses code without looking over it first. Thanks for the input.

Share this post


Link to post
Share on other sites
Uh, cubicool.... The only compiler I know of that supports "export" is the latest version of Comeau C++ (a very expensive commercial compiler), and to say that that''s the only "good" compiler is incredibly naive, obviously since he asking for help with some school assignment, he should not be using any code with "export" in it, since his code probably has to compile on GCC (which unis love to use...).

Share this post


Link to post
Share on other sites
Comeau C++ may support "export", but that doesn''t mean anything.
Visual Studio .NET 2003 and GCC 3.4 are way more standard compliant (they accept much more code)
Also there was an article on gotw.ca that states that "export" will be removed from the standard, because it has no uses and only makes compiler writing much more difficult.

Share this post


Link to post
Share on other sites
Well, foo.

I''m certain I''ve used it before, and that was LONG ago, in my FreeBSD days w/ gcc3.0--or thereabouts.

<-- ass

I don''t do much work w/ templates, but when I did, I always exported them. I don''t think I could stomach headers will the implementations.

Maybe I was just schooled wrong? *sigh*

Share this post


Link to post
Share on other sites
Comeau C++ supports "export" since a year or something...
So it can't be "long" ago. And there are NO other compilers that supports it.

quote:
in my FreeBSD days w/ gcc3.0

GCC 3.0 certainly supports NO "export".

[edited by - noVum on October 13, 2003 11:17:57 AM]

Share this post


Link to post
Share on other sites