Advertisement

templated class g++ problem

Started by October 10, 2003 06:05 PM
10 comments, last by doodah2001 20 years, 11 months ago
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.
MatDoodah2001@hotmail.comLife is only as fun as you make it!!!
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"?

Advertisement
You don''t put template implementations in .cpp files, they have to be in the .hpp.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.

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.
MatDoodah2001@hotmail.comLife is only as fun as you make it!!!
Good compilers support "export."

Seperate declarations and implementations, even w/ templates.
Advertisement
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...).
still?

[edited by - cubicool on October 12, 2003 12:40:00 PM]
Not to be a snot, but Comeau C++ is actually only $50. It is not THAT expensive. Definitely not as expensive as MSVC 6 pro that I just bought off of ebay. ;-)
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.

This topic is closed to new replies.

Advertisement