www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/25/16:17:20

From: bryan AT alpha DOT hcst DOT com (Bryan Murphy)
Newsgroups: comp.os.msdos.djgpp
Subject: Problem Compiling with C++ (more detailed)
Date: 25 Feb 1997 13:48:45 -0500
Organization: Hassler Communication Systems Technology, Inc.
Lines: 68
Message-ID: <5evc6d$ed4@alpha.hcst.com>
NNTP-Posting-Host: alpha.hcst.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Ok, here is an example of the problem I am having compiling and
linking my code.  I'm starting to think it has something to do 
with the templates, but I'm unsure why, as I could only reproduce
this error when using them. 

/***** FILE: classlib.h ************************************************/
#ifndef _CLASSLIB
#define _CLASSLIB

#include "iostream.h"

template<class TYPE>
class TESTCLASS
{
public:
	TESTCLASS(char *newname);
	void PrintName();
        void InlinePrint() { cout << "Inline: " << name << endl; };
        void StoreData(TYPE newdata) { data = newdata; }

private:
	char *name;
        TYPE data;
};

#endif

/***** FILE: classlib.cc ***********************************************/
#include "classlib.h"
#include "string.h"

template<class TYPE>
TESTCLASS<TYPE>::TESTCLASS(char *newname)
{
	name = new char[strlen(newname)];
	strcpy(name,newname);
};

template<class TYPE>
void TESTCLASS<TYPE>::PrintName()
{
	cout << name << endl;
};


/***** FILE: test.cc **************************************************/
#include "classlib.h"

void main()
{
	cout << "This should compile correctly, link and run." << endl;

        TESTCLASS<int> Test("This is my Name");

        Test.PrintName();
        Test.InlinePrint();
        Test.StoreData(10);
};

/***** Compilation Output ***********************************************/

gcc test.cc classlib.cc -lgpp

c:/djgpp/tmp\ccdaaaaa(.text+0x7a):test.cc: undefined reference to `TESTCLASS<int>::TESTCLASS(char *)'
c:/djgpp/tmp\ccdaaaaa(.text+0x86):test.cc: undefined reference to `TESTCLASS<int>::PrintName(void)'


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019