473,396 Members | 2,010 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,396 software developers and data experts.

need help about template class

Hi all
when I wrote this 2 lines code in one file, it compiles fine.

template <class Tclass A {};
class B: A<int{};

however
when I put this code in one file,
template <class Tclass A {};

this code in another file
template <class Tclass A;
class B: A<int{};

it complains that
M:\zz\clang>g++ tem.cpp tem2.cpp
tem2.cpp:3: base class `A<int>' has incomplete type

M:\zz\clang>g++ -v
Reading specs from D:/MinGW/bin/../lib/gcc-lib/mingw32/3.2.3/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld
--with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable
-languages=c++,f77,objc --disable-win32-registry --disable-shared
--enable-sjlj-
exceptions
Thread model: win32
gcc version 3.2.3 (mingw special 20030504-1)
what does this mean? "base class `A<int>' has incomplete type"
any lights much appreciated!

Oct 19 '06 #1
2 1436
yichao.zhang wrote:
Hi all
when I wrote this 2 lines code in one file, it compiles fine.

template <class Tclass A {};
class B: A<int{};

however
when I put this code in one file,
template <class Tclass A {};

this code in another file
template <class Tclass A;
class B: A<int{};

it complains that
M:\zz\clang>g++ tem.cpp tem2.cpp
tem2.cpp:3: base class `A<int>' has incomplete type
[...]
what does this mean? "base class `A<int>' has incomplete type"
any lights much appreciated!
It means that you have *declared* A<in the second file but have not
*defined* it. To use the class (e.g., by inheriting from it or creating
an instance), it needs to be *defined* in the current translation unit.
Probable fix: include the first file (which is presumably a header
file, since g++ doesn't support export as far as I know; cf.
http://www.parashift.com/c++-faq-lit...html#faq-35.14) in the
second.

Cheers! --M

Oct 19 '06 #2
thanks mlimber.
the link you post is very useful too.

Oct 19 '06 #3

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

Similar topics

3
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules...
1
by: David2511 | last post by:
Hello, I need a little help. I try to write the following architecture : an abstract template class A Two classes derived from class A : the classes B and C which are concrete. The class...
5
by: Tony Johansson | last post by:
Hello experts! I have two class template below with names Array and CheckedArray. The class template CheckedArray is derived from the class template Array which is the base class This program...
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
14
by: key9 | last post by:
Hi All On coding , I think I need some basic help about how to write member function . I've readed the FAQ, but I am still confuse about it when coding(reference / pointer /instance) , so I...
12
by: nephish | last post by:
Hello there, i am getting to need to make my web stuff more OO. i have a project at work that we are porting to the internet, and i started learning php to do so. the project is now mamoth is...
5
by: aaragon | last post by:
Hello everybody, I appreciate your taking the time to take a look at this example. I need some help to start the design of an application. To that purpose I'm using policy-based design. The...
15
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object...
4
by: parag_paul | last post by:
hi All , I am giving the pseudo code about the problem I am talking about . I have a class hiearchy which looks like this. class A; template <class X1, class X2class B : public A{}
8
by: Jim Cobban | last post by:
I am writing a program in which I need a hash table implementation of a Map. The version of g++ available for Windo$e does not yet include the TR1 support for this. It just has the original SGI...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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.