Sorry if this is a little off topic. I have none experience with gcc, and very little experience with c++. So I am experimenting a bit. I have done a class template, Matrix,and everything is good with it. Just to try, I have derived from this class template a common class, called Relation. As a relation is rapresented as a matrix of double, I have derived it from Matrix<double>. My syntax is good, so I do not receive any error when I compile the relation.cpp file. The problem comes out at linking time: every function which is inherited by Matrix <double> and not redefined causes an error: "home/praise/fuzzycmeans/fuzzycmeans/relation.cpp:42: undefined reference to `Matrix<double>::at(int, int) const' I also have these errors: /usr/include/g++/stl_alloc.h(.text+0xf): undefined reference to `Matrix<double>::Matrix(void)' /usr/include/g++/stl_alloc.h(.text+0x37): undefined reference to `Matrix<double>::~Matrix(void)' /usr/include/g++/stl_alloc.h(.gnu.linkonce.d.__vt_9Relazione+0x24): undefined reference to `Matrix<double>::operator[](int) const' I do not know what this means. Anyone could help? Praise
On Fri, Apr 05, 2002 at 10:43:29PM +0200, Praise wrote:
Sorry if this is a little off topic.
I have none experience with gcc, and very little experience with c++. So I am experimenting a bit. I have done a class template, Matrix,and everything is good with it. Just to try, I have derived from this class template a common class, called Relation. As a relation is rapresented as a matrix of double, I have derived it from Matrix<double>. My syntax is good, so I do not receive any error when I compile the relation.cpp file. The problem comes out at linking time: every function which is inherited by Matrix <double> and not redefined causes an error:
"home/praise/fuzzycmeans/fuzzycmeans/relation.cpp:42: undefined reference to `Matrix<double>::at(int, int) const'
I also have these errors: /usr/include/g++/stl_alloc.h(.text+0xf): undefined reference to `Matrix<double>::Matrix(void)' /usr/include/g++/stl_alloc.h(.text+0x37): undefined reference to `Matrix<double>::~Matrix(void)'
/usr/include/g++/stl_alloc.h(.gnu.linkonce.d.__vt_9Relazione+0x24): undefined reference to `Matrix<double>::operator[](int) const'
I do not know what this means. Anyone could help?
If you can reduce your problem to a test case of just a few lines it would be easier for someone else to diagnose. Also, you might get better response from the newsgroup comp.lang.c++ -- Robert C. Paulsen, Jr. robert@paulsenonline.net old -> paulsen@texas.net
This may be a bit snobbish, but there are plenty of news groups for C and C++. Additionally, it appears that you are just learning to program. I suggest that you either take a course or at least buy a good book on learning C++. That said: First, writing templates to start learing C++ is probably not a good idea. But, the type of error you have is that C++ classes must have constructors and, in some cases, destructors. Each of these methods have their own signatures. On 5 Apr 2002 at 22:43, Praise wrote:
Sorry if this is a little off topic.
I have none experience with gcc, and very little experience with c++. So I am experimenting a bit.
-- Jerry Feldman Portfolio Partner Engineering 508-467-4315 http://www.testdrive.compaq.com/linux/ Compaq Computer Corp. 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752
Il 23:36, venerdì 5 aprile 2002, Jerry Feldman ha scritto:
Additionally, it appears that you are just learning to program. I suggest that you either take a course or at least buy a good book on learning C++. That said: First, writing templates to start learing C++ is probably not a good idea.
I have already done some C++ in the past. Just not templates. The problem is not with C++ itself, just with the linker.
But, the type of error you have is that C++ classes must have constructors and, in some cases, destructors. Each of these methods have their own signatures.
And they obviously work when alone. They are there, the only one who do not look at them is the linker. (and the includes are obviously there).
On Sat, Apr 06, 2002 at 01:41:10AM +0200, Praise wrote:
Il 23:36, venerdì 5 aprile 2002, Jerry Feldman ha scritto:
Additionally, it appears that you are just learning to program. I suggest that you either take a course or at least buy a good book on learning C++. That said: First, writing templates to start learing C++ is probably not a good idea.
I have already done some C++ in the past. Just not templates. The problem is not with C++ itself, just with the linker.
I cannot answer your question. I have not used template classes before. I can recommend a news group that might be able to help though. Check out comp.unix.programmer . If this is a g++ quirk or something, then the people who post there would probably know. -v -- Victor R. Cardona Powered by SuSE Linux 7.1 (i386) Professional GPG key ID E81B3A1C Key fingerprint = 0147 A234 99C3 F4C5 BC64 F501 654F DB49 E81B 3A1C
Praise
I have already done some C++ in the past. Just not templates. The problem is not with C++ itself, just with the linker.
I really doubt that it's a problem with the linker. Remember that the compiler has to see all the code for the template as no current compiler supports the export keyword. So either implement the code fully in a header or have the header include the complete template code. If that isn't the reason, I'd have to see the source code to possibly offer additional advice. Philipp
As I mentioned, I don't think this is an appropriate forum for this. Briefly though: The compiler generates a unique signature for each method. From what you posted before, it appears that the instansiation of your template did not include the appropriate constructor and destructor. Possibly, the base class may have declared them as virtual. On 6 Apr 2002 at 1:41, Praise wrote:
Il 23:36, venerdì 5 aprile 2002, Jerry Feldman ha scritto:
Additionally, it appears that you are just learning to program. I suggest that you either take a course or at least buy a good book on learning C++. That said: First, writing templates to start learing C++ is probably not a good idea.
I have already done some C++ in the past. Just not templates. The problem is not with C++ itself, just with the linker.
But, the type of error you have is that C++ classes must have constructors and, in some cases, destructors. Each of these methods have their own signatures.
And they obviously work when alone. They are there, the only one who do not look at them is the linker. (and the includes are obviously there).
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com
-- Jerry Feldman Portfolio Partner Engineering 508-467-4315 http://www.testdrive.compaq.com/linux/ Compaq Computer Corp. 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752
I would recommend learning OOP with Python. Then when you get the gist of it, you can do Java or C++. Python makes OOP very easy. You may even stick with it. There are lots of Python packages for interface to GTK, WxWindows, and other neat GUI stuff. www.python.org. Rob. Jerry Feldman wrote:
This may be a bit snobbish, but there are plenty of news groups for C and C++. Additionally, it appears that you are just learning to program. I suggest that you either take a course or at least buy a good book on learning C++. That said: First, writing templates to start learing C++ is probably not a good idea. But, the type of error you have is that C++ classes must have constructors and, in some cases, destructors. Each of these methods have their own signatures.
On 5 Apr 2002 at 22:43, Praise wrote:
Sorry if this is a little off topic.
I have none experience with gcc, and very little experience with c++. So I am experimenting a bit.
-- Jerry Feldman Portfolio Partner Engineering 508-467-4315 http://www.testdrive.compaq.com/linux/ Compaq Computer Corp. 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com
-- ------------------------- Numeric Python EM Project www.pythonemproject.com
participants (6)
-
Jerry Feldman
-
Philipp Thomas
-
Praise
-
rob
-
Robert C. Paulsen Jr.
-
Victor R. Cardona