944,150 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 517
  • C++ RSS
Oct 16th, 2009
0

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

Expand Post »
With this code:
http://www.rpi.edu/~doriad/Daniweb/maxflow/
If I run
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
Oct 16th, 2009
-7
Re: Code compiles with g++ 3.3 but not g++ 4.4
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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Oct 17th, 2009
0
Re: Code compiles with g++ 3.3 but not g++ 4.4
I had to instantiate the constructor by adding this to the instances.inc file:
C++ Syntax (Toggle Plain Text)
  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
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
Oct 17th, 2009
0
Re: Code compiles with g++ 3.3 but not g++ 4.4
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. ]
Reputation Points: 749
Solved Threads: 135
Practically a Master Poster
StuXYZ is offline Offline
660 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help me out in oo in c++
Next Thread in C++ Forum Timeline: Callback issues





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC