473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

template with static member

The following code gives the link error:

[Linker Error] Unresolved external 'C1<int>::f()' referenced from D:\PROGRAM
FILES\BORLAND\CBUILDER5\PROJECTS\MAIN.OBJ

Using Borland CBuilder5. If i define the body of the function f in the
header file1.h, it links ok. I believe this is normal language behaviour
because all the ATL libs are defined in the headers. But is there another
way to do it so i can define my functions in the cpp file?

file1.h:
/////////////////////////////////
template<class T>
class C1
{
public:
static void f();
};
/////////////////////////////////

file1.cpp:
/////////////////////////////////
template<class T>
void C1<T>::f()
{
}
/////////////////////////////////

main.cpp:
/////////////////////////////////
#include "file1.h"

int main(int argc, char* argv[])
{
C1::f();
return 0;
}
Jul 19 '05 #1
2 2038

"Patrick McConnell" <pm***********@epacsten.com> wrote in message
news:be**********@news.eusc.inter.net...
The following code gives the link error:

[Linker Error] Unresolved external 'C1<int>::f()' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\MAIN.OBJ

Using Borland CBuilder5. If i define the body of the function f in the
header file1.h, it links ok. I believe this is normal language behaviour
because all the ATL libs are defined in the headers. But is there another
way to do it so i can define my functions in the cpp file?


No, templates must go in the header file.

There is an export keyword that is supposed to handle this but

a) its contrversial
b) only one compiler supports it (and its not borland)

john
Jul 19 '05 #2

"John Harrison" <jo*************@hotmail.com> wrote in message
news:be************@ID-196037.news.uni-berlin.de...

There is an export keyword that is supposed to handle this but

a) its contrversial
b) only one compiler supports it (and its not borland)

At least two :). EDG has its own back-ends too.

--
With regards,
Michael Kochetkov.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gianni Mariani | last post by:
I remember seeing a neat template specialization trick posted here a few months ago that allowed the detection of a type containing a member. After a day searching through google archives I come up...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
0
by: Chris F Clark | last post by:
In our C++ project we have some internal bug reporting macros that we use to get useful information when the program does something unexpected. Essentially at the point of the error, we invoke an...
7
by: ank | last post by:
Hi, I was curious about how to define static data member of template class. Should I put the definition in a separate source file or in the same header file as its template class? And when this...
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
2
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just...
1
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
5
by: chgans | last post by:
Hi all, I'm having difficulties with some template static member, especially when this member is a template instance, for example: ---- template<typename T> class BaseT { public: static...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.