| | |
Code compiles with g++ 3.3 but not g++ 4.4
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 628
Reputation:
Solved Threads: 46
With this code:
http://www.rpi.edu/~doriad/Daniweb/maxflow/
If I run
with g++ 3.3, everything works fine. However if I run the same command with g++ 4.4, I get this error:
Does anyone know how I can get this to work with g++ 4.4?
Thanks!
David
http://www.rpi.edu/~doriad/Daniweb/maxflow/
If I run
C++ Syntax (Toggle Plain Text)
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)
Example.cpp:(.text+0x38): undefined reference to `Graph<int, int, int>::Graph(int, int, void (*)(char*))'
Does anyone know how I can get this to work with g++ 4.4?
Thanks!
David
•
•
Join Date: Feb 2008
Posts: 628
Reputation:
Solved Threads: 46
0
#3 Oct 17th, 2009
I had to instantiate the constructor by adding this to the instances.inc file:
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
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
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.
[in the same way that if you provide an explicit template function you should not explicitly instantiate it. ]
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
![]() |
Similar Threads
- Finished my code, it compiles, but when i use build bersion, there is always an error (C++)
- error code (C++)
- need help on my code about word frequency counter (C++)
- this code does not work help me pls (C)
- Having a little trouble with my Code. [please Help me out] (C++)
- How do you write a code which compiles in c but not in c++? (C++)
Other Threads in the C++ Forum
- Previous Thread: help me out in oo in c++
- Next Thread: Callback issues
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






