| | |
instances.inc?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 638
Reputation:
Solved Threads: 46
I am trying to compile some code (Example.cpp from here: http://www.rpi.edu/~doriad/Daniweb/maxflow/). I am getting
This is clearly a template instantiation problem. I see that there is a file called instances.inc that defines the <int,int,int> class, do I need to somehow tell gcc/g++ to use this file? Or how else could I get this to work?
Thanks,
Dave
C++ Syntax (Toggle Plain Text)
Example.cpp:(.text+0x38): undefined reference to `Graph<int, int, int>::Graph(int, int, void (*)(char*))'
This is clearly a template instantiation problem. I see that there is a file called instances.inc that defines the <int,int,int> class, do I need to somehow tell gcc/g++ to use this file? Or how else could I get this to work?
Thanks,
Dave
•
•
Join Date: Feb 2008
Posts: 638
Reputation:
Solved Threads: 46
0
#2 Oct 9th, 2009
Here is a simplified version that produces the error:
graph.h
graph.cpp
instances.inc
Example.cpp
Any ideas?
Thanks,
Dave
graph.h
C++ Syntax (Toggle Plain Text)
#include <string.h> template <typename captype, typename tcaptype, typename flowtype> class Graph { public: Graph(int node_num_max, int edge_num_max, void (*err_function)(char *) = NULL); };
graph.cpp
C++ Syntax (Toggle Plain Text)
#include "graph.h" #include "instances.inc" template <typename captype, typename tcaptype, typename flowtype> Graph<captype, tcaptype, flowtype>::Graph(int node_num_max, int edge_num_max, void (*err_function)(char *)) { }
instances.inc
C++ Syntax (Toggle Plain Text)
#include "graph.h" template class Graph<int,int,int>; template class Graph<short,int,int>; template class Graph<float,float,float>; template class Graph<double,double,double>;
Example.cpp
C++ Syntax (Toggle Plain Text)
#include <stdio.h> #include "graph.h" int main() { typedef Graph<int,int,int> GraphType; GraphType *g = new GraphType(/*estimated # of nodes*/ 2, /*estimated # of edges*/ 1); return 0; }
Any ideas?
Thanks,
Dave
0
#4 Oct 12th, 2009
are u compiling it as
If not then do it like that.
C++ Syntax (Toggle Plain Text)
c++ Example.cpp graph.cpp
Last edited by dkalita; Oct 12th, 2009 at 8:33 am.
•
•
Join Date: Feb 2008
Posts: 638
Reputation:
Solved Threads: 46
0
#5 Oct 12th, 2009
I am doing that:
Can anyone confirm this behavior?
C++ Syntax (Toggle Plain Text)
[doriad@davedesktop test]$ g++ Example.cpp graph.cpp /tmp/ccHbyqCi.o: In function `main': Example.cpp:(.text+0x38): undefined reference to `Graph<int, int, int>::Graph(int, int, void (*)(char*))' collect2: ld returned 1 exit status
Can anyone confirm this behavior?
0
#6 Oct 12th, 2009
•
•
•
•
C++ Syntax (Toggle Plain Text)
GraphType *g = new GraphType(/*estimated # of nodes*/ 2, /*estimated # of edges*/ 1);
C++ Syntax (Toggle Plain Text)
Graph<captype, tcaptype, flowtype>::Graph(int, int);
C++ Syntax (Toggle Plain Text)
Graph<captype, tcaptype, flowtype>::Graph(int , int, void (*err_function)(char *));
•
•
Join Date: Feb 2008
Posts: 638
Reputation:
Solved Threads: 46
0
#7 Oct 12th, 2009
I dont think so ...
The constructor is actually:
which is an optional parameter, no? Hence it should be fine to call it with only 2 ints?
The constructor is actually:
C++ Syntax (Toggle Plain Text)
Graph(int node_num_max, int edge_num_max, void (*err_function)(char *) = NULL);
which is an optional parameter, no? Hence it should be fine to call it with only 2 ints?
0
#8 Oct 12th, 2009
•
•
•
•
I dont think so ...
The constructor is actually:
C++ Syntax (Toggle Plain Text)
Graph(int node_num_max, int edge_num_max, void (*err_function)(char *) = NULL);
which is an optional parameter, no? Hence it should be fine to call it with only 2 ints?
The file graph.h is getting included twice in graph.cpp beacuse u are including it from instances.inc also.
Remove the
C++ Syntax (Toggle Plain Text)
#include"graph.h"
I tried it in my compiler and i didn't get any error.
NB: whenever u are making some header file its good to define a macro such that
example.h
C++ Syntax (Toggle Plain Text)
#ifndef EXAMPLE_H #define EXAMPLE_H /*prototypes*/ #endif
Last edited by dkalita; Oct 12th, 2009 at 9:20 am.
•
•
Join Date: Feb 2008
Posts: 638
Reputation:
Solved Threads: 46
0
#9 Oct 12th, 2009
I'm still getting the same error. Can someone try these files:
http://www.rpi.edu/~doriad/Daniweb/maxflow/
with
http://www.rpi.edu/~doriad/Daniweb/maxflow/
with
C++ Syntax (Toggle Plain Text)
g++ Example.cpp graph.cpp
0
#10 Oct 12th, 2009
•
•
•
•
I'm still getting the same error. Can someone try these files:
http://www.rpi.edu/~doriad/Daniweb/maxflow/
with
C++ Syntax (Toggle Plain Text)
g++ Example.cpp graph.cpp
C++ Syntax (Toggle Plain Text)
myself@king [70]g++ Example.cpp graph.cpp myself@king [71]
![]() |
Similar Threads
- Does this really generate multiple instances of a UNIX process (Perl)
- to solve instances of size 200 in 1 minute (Computer Science)
- JRE vs Class Instances in RAM (Java)
- GTK code uses pointer for structs and not normal instances why? (C)
- multiple program instances opening on their own (Windows NT / 2000 / XP)
- Database design - subtypes and instances of an entity (Database Design)
- Passing Class Objects, Instances (C++)
- Multiple Instances of OUTLOOK.EXE (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: ascending order
- Next Thread: Multimap problem
Views: 410 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





