473,396 Members | 2,061 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.

Self reference in Template class?

nw
Hi comp.lang.c++,

I have the following header (simple.h):

#ifndef SIMPLE
#define SIMPLE

template<class _prec=double>
class Simple {

public:

Simple() {
}

Simple<_precnext;
};

#endif

and c++ file:

#include <iostream>
#include "simple.h"

using namespace std;

int main() {
Simple<doubles;
}
Compilation gives me the error:

simple.h: In instantiation of 'Simple<double>':
simple.cpp:7: instantiated from here
simple.h:12: error: 'Simple<_prec>::next' has incomplete type
simple.h:5: error: declaration of 'class Simple<double>'

under g++ 4.1.2. I guess I need to add a prototype for Simple, but I
can't quite see how to do this for a template class. Any help
appreciated!
Jun 27 '08 #1
1 2468
nw wrote:
Hi comp.lang.c++,

I have the following header (simple.h):

#ifndef SIMPLE
#define SIMPLE

template<class _prec=double>
class Simple {

public:

Simple() {
}

Simple<_precnext;
};

#endif

and c++ file:

#include <iostream>
#include "simple.h"

using namespace std;

int main() {
Simple<doubles;
}
Compilation gives me the error:

simple.h: In instantiation of 'Simple<double>':
simple.cpp:7: instantiated from here
simple.h:12: error: 'Simple<_prec>::next' has incomplete type
simple.h:5: error: declaration of 'class Simple<double>'

under g++ 4.1.2. I guess I need to add a prototype for Simple, but I
can't quite see how to do this for a template class. Any help
appreciated!
You cannot do this. Declare next as a pointer or reference type (and
make sure the pointee is always valid of course during runtime).

Fei
Jun 27 '08 #2

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

Similar topics

1
by: SpeedBump | last post by:
This is mostly just another "gee it would be nice if it had X" post. Recently I have come across two separate problems which both exhibit the need for a way to self reference when instantiating a...
2
by: Agent Mulder | last post by:
Hi group, I try to get a reference to a template. In the template, a virtual function is declared. Later in the program, I inherit from classes created by the template. So the template is the...
1
by: Greg Phillips | last post by:
Hello everyone, I have read the section on templates in The C++ Programming Language 3rd edition 3 times over the last 4 days. Still I am stumped. I'll explain a bit about what I am doing...
8
by: JKop | last post by:
Having decided not to use macros at all in designing my reseatable references, and having looked through the list of overloadable operators and combinations of them, I've settled on the following...
20
by: Wayne Sutton | last post by:
OK, I'm a newbie... I'm trying to learn Python & have had fun with it so far. But I'm having trouble following the many code examples with the object "self." Can someone explain this usage in...
34
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
3
by: IR | last post by:
Hi, I've been trying to do the following (which doesn't compile) : template<class T, class F = Example<T struct Example { F foo(); };
7
by: comp.lang.php | last post by:
<? class EditResultGenerator extends MethodGeneratorForActionPerformer { /** * Create an instance of itself if $this does not yet exist as an EditResultGenerator class object * * @access...
1
by: PeterAPIIT | last post by:
What is template template arguments and template typename arguments ? The reason i write in policy based design is because this is the requirement of the assignment. My code so far: ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.