Code compiles with g++ 3.3 but not g++ 4.4

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Code compiles with g++ 3.3 but not g++ 4.4

 
0
  #1
Oct 16th, 2009
With this code:
http://www.rpi.edu/~doriad/Daniweb/maxflow/
If I run
  1. g++ Example.cpp graph.cpp

with g++ 3.3, everything works fine. However if I run the same command with g++ 4.4, I get this error:
  1. Example.cpp:(.text+0x38): undefined reference to `Graph<int, int, int>::Graph(int, int, void (*)(char*))'
  2.  

Does anyone know how I can get this to work with g++ 4.4?

Thanks!

David
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,363
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning
 
-7
  #2
Oct 16th, 2009
It compiles ok with VC++2008 Express too. I don't have g++ 4.4 so I can't test it.
Last edited by Ancient Dragon; Oct 16th, 2009 at 2:47 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster
 
0
  #3
Oct 17th, 2009
I had to instantiate the constructor by adding this to the instances.inc file:
  1. template Graph<int,int,int>::Graph(int, int, void (*)(char *));

Does anyone understand why / know if the compiler can be told to do this automatically? I thought the whole point of templates was so you did NOT have to know the types that would be used?

Thanks,

Dave
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 392
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz
 
0
  #4
Oct 17th, 2009
The reason (for good/bad) is that when the compiler hits instances.inc.
It has not seen the definition of graph.
If you put include instances at the end of graph.cpp all is fine.

Note that you only need the template instance for the class e.g.
template class Graph<int,int,int>; since all the methods for the class are build. This should have been flaged as an error by VC++.
[in the same way that if you provide an explicit template function you should not explicitly instantiate it. ]
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC