Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-16-2004, 02:32 AM   #1
Registered: Jul 2004
Posts: 60

Rep: Reputation: 15
c++ template help


Ive been yanking my brains on this stupid error since 6 hrs streight, and I havent reached no where. Can some guru please help me out....? Im sure its something cause I get this freaking referencing error even when eventhing (except the construcor) has been comented.

Thanks guys

//   BinomialNode.h

#include <iostream>
template <typename Type>
class BinomialNode {
        BinomialNode( );

#include "BinomialNode.h"
#include <iostream>

using namespace std;
template BinomialNode<int>;

*       Default Constructor
*       PRE:    none
*       POST:   Instance of BinomialNode with no siblings,
*                       children or parent.
template <typename Type>

//         ERROR MESSAGE
g++ -R/util/gnu/lib -Wno-non-template-friend  -g -c Driver.cpp 
g++ -R/util/gnu/lib -Wno-non-template-friend  -g -o Driver Driver.o  
Undefined                       first referenced
 symbol                             in file
ld: fatal: Symbol referencing errors. No output written to Driver
collect2: ld returned 1 exit status
gmake: *** [Driver] Error 1
Old 11-16-2004, 03:46 AM   #2
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
havnt done anything with templates in a while but if i remember right any templated member functions must be in the header file, not the implementation file, im sure someone whos done stuff more recently can either correct or elaborate on that though.
Old 11-16-2004, 04:13 AM   #3
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
This is a linker error, which means that you're using a symbol that you haven't defined.

First of all, in any program, you need one of the following functions; it won't link without exactly one of these:
int main();
int main(int argc);
int main(int argc, char** argv );
int main(int argc, char** argv, char** envp);
The symbol it's complaining about is the BinomialNode<int>::BinomialNode() constructor; since you haven't used BinomialNode<int> anywhere in your code, it's difficult to see why this error occurs.

You might try moving the implementation to the header file; though I don't recall that limitation myself, there is a thread on it here:
Old 11-16-2004, 08:17 AM   #4
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
kev82 is correct. Templated classes must be implemented completely in the header file. The link in the response above discusses a bit more on why that is...

Last edited by deiussum; 11-16-2004 at 08:19 AM.
Old 11-16-2004, 08:52 AM   #5
Registered: Jul 2004
Posts: 60

Original Poster
Rep: Reputation: 15
Thanks for the replies guys, I finally got it working. The issue wasnt only the "int main()" thing, but it seems i also had to implement the .cpp file at the end of the header file. Found this tip on one of the websites. Thanks a lot for the replies....


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Daemon Template thekonqueror Programming 0 08-15-2005 02:07 PM
Template class with a template member... Nicholas Bishop Programming 3 02-21-2005 08:27 PM
user template bogus__13 Linux - General 5 01-21-2005 01:25 AM
template class ckcheung0927 Programming 3 11-28-2004 03:59 PM
HTML::Template smalter Programming 0 06-14-2001 10:41 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration