www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/11/03:11:58

Date: Thu, 8 May 1997 23:13:03 +0200 (CEST)
From: matra <matra AT diemme DOT it>
To: djgpp AT delorie DOT com
Subject: djgpp & templates
Message-ID: <Pine.BSF.3.95q.970508231226.273B-100000@rook.matranet.org>
MIME-Version: 1.0

Hi!

Im a C user of Djgpp that has to switch to C++ for some projects . 
Can any1 help me using templates with djgpp 2.7.2 og g++ 2.7.2.1 under
FreeBSD ? 

This is my problem : this simple class doesn't compile ! 

WHY!??? ... :-<<<<

(file "myclass.cc")
#include "myclass.h"

template <class T> myclass<T>::myclass(T tinf)
{
	cout << "Hello World!" << endl;
	inf = tinf;
}


(file "mytest.cc")
#include "myclass.h"

int main(void)
{
	myclass<int> myc(3);

	return 0;
}


(file "myclass.h");
#include <iostream.h>

template <class T>
class myclass
{
public:
	myclass(T);    
private:
	T inf;
};

class myclass<int>;  // without this the linker says "undefined reference"!!!

...and this is the compile result (same under djgpp/g++):

[matra] $ g++ myclass.cc mytest.cc -o mytest
mytest.cc: In function `int main()':
mytest.cc:5: variable `class myclass<int> myc' has initializer but incomplete type
mytest.cc:5: aggregate `class myclass<int> myc' has incomplete type and cannot be initialized

Can any1 help me posting a WORKING example of templates under djgpp? 

hoping for help...

cul8r




- Raw text -


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