473,387 Members | 1,766 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,387 software developers and data experts.

tamplate class error: "undefined reference"

Hi!

I hope the solution to that is not too stupid... I've got three files:

<snip test_main.cc>
#include"test.hh"
int main(void)
{
A<inta1;
a1.saywhat();
return 0;
}
</snip>

<snap test.hh>
#ifndef _A_HH_
#define _A_HH_
#include<iostream>
using namespace std;
template<typename T>
class A
{
public:
A();
virtual ~A();
void saywhat();
private:
double m_a;
};
#endif
</snap>

<snup test.cc>
#include"test.hh"

template<typename T>
A<T>::A()
{
m_a=23;
cout << "const" << endl;
}

template<typename T>
A<T>::~A()
{
cout << "dest" << endl;
}

template<typename T>
void A<T>::saywhat()
{
cout << "saywhat:" << m_a << endl;
}
</snup>

when I compile with g++ version 4.1.2 20061028
# g++ test.cc test_main.cc
I get the following errors

/tmp/cc7Ejh47.o: In function `main':
test_main.cc:(.text+0x8b): undefined reference to `A<int>::A()'
test_main.cc:(.text+0x96): undefined reference to `A<int>::saywhat()'
test_main.cc:(.text+0xa6): undefined reference to `A<int>::~A()'
test_main.cc:(.text+0xbc): undefined reference to `A<int>::~A()'
collect2: ld returned 1 exit status

interestingly, when I #include"test.cc" in the test_main.cc, the
program compiles and runs fine! But that's not how it's supposed to
be...

What the $(%&§)$ am I doing wrong?

Thanks in advance!

Steffen

Dec 5 '06 #1
3 2027
s.***@web.de wrote:
[...link errors when placing templates in separate TU...]

What the $(%&§)$ am I doing wrong?
You're not reading the FAQ before posting.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 5 '06 #2
* s.***@web.de:
>
What the $(%&§)$ am I doing wrong?
FAQ item 35.12.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 5 '06 #3
Thanks, and sorry for not checking the faq!

steffen

Dec 5 '06 #4

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

Similar topics

13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
4
by: Flip | last post by:
I'm seeing one of my websites giving me an error message on the page after it loads up as "WXBUnit Undefined" What does that mean? The formatting of the site is horrible! I'm not sure what is...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
8
by: Soneji | last post by:
Hello all! ( again ) Once more, I have a problem that seems unsolvable by me. I'm getting the, seemingly common, "undefined reference" linking error. I've tried quite a few things, but...
16
by: Micko1 | last post by:
Hello there :) I have been using Visual Studio on a program which I have just completed, however I need to have it compiling using a unix based compiler, when I try in cygwin, I get the following...
2
by: =?Utf-8?B?UGF1bCBMaW52aWxsZQ==?= | last post by:
I have a solution that has both c# and vb.net projects. Visual Studio 2005 sp1. One of the lower level asseblies "Utils.csproj" is a c# project that references a 3rd party dll "Framework.dll"....
8
Motoma
by: Motoma | last post by:
Good evening everyone. I am starting to re-explore C++, and I wanted to build a singleton class. Unfortunately, when I set things up as I do in PHP, it doesn't work out for me. I hope that the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.