www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/02/11:48:46

From: bena AT NOSPAMsirplc DOT co DOT uk (Ben Ashley)
Newsgroups: comp.os.msdos.djgpp
Subject: Template Classes
Date: Tue, 02 Dec 1997 12:35:27 GMT
Organization: Systems Integrated Research Plc
Lines: 118
Message-ID: <3483fe9f.11764438@news.areti.co.uk>
Reply-To: bena AT sirplcNOSPAM DOT co DOT uk
NNTP-Posting-Host: 194.130.222.18
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hey All,

Over the past few days I have been developing some template classes
with DJGPP.  Unfortunately, I have been hitting a few problems.

At first, I was getting an undefined reference to whatever member
function I was accessing.  To get around this, the solution seemed to
be to either include all functions definitions, in the declaration of
the class, ie:


template< class TYPE >class A
{
public:
	A()
	{
		// A Constructor
	};

	~A()
	{
		// A Destructor
	};


	void AFunction()
	{
		// A Function
	};


	// etc...
};


This, however, looked horrid, and could very quickly become
unmanageable...  An alternative method was to split them up into the
usual .h, and .cc file, but implictily include the .cc file in the .h
file....



File: a.h
---------

template< class TYPE >class A
{
public:
	A();
	~A();

	void AFunction();
};


#ifndef A_IMPLEMENTATION
#define A_IMPLEMENTATION

#include "a.cc"

#endif // A_IMPLEMENTATION



File: a.cc
----------


template< class TYPE >
A< TYPE >::A()
{
	// A Constructor
};


template< class TYPE >
A< TYPE >::~A()
{
	// A 
};


template< class TYPE >
void A< TYPE >::AFunction()
{
	// Some meaningless function
};




However, the problem with both of the above methods is the overhead of
the object files.  Surely, having the implementation with the header
file ( same in both cases ), will mean that each object file that
includes these files will have the entire implementation aswell.

Will DJGPP strip out the extra stuff at link time?  Does it have the
intelligence to realise that alot of the content in these object files
is similar?

Is there a method whereby I don't have to include the implementation
to be able to use template-class functionality?

I did read up on the Template Instantation section of the DJGPP
documentation, but unfortunately, like the rest of the DJGPP
documentation, it leaves a lot to be desired.

Anyone's comments would be gratefully appreciated.



Cheers,


Ben Ashley -  (Anti-Spam EMail Address.  Remove 'NOSPAM')

Programmer for Systems Integrated Research Plc
"Winnie says he's *Not* In-Animate"

- Raw text -


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