Hello, I was wondering if it is possible to forward declare a type
definition. If so, what is the way to do it? I found a couple of
messages where they say it's not possible but there must be a way to
do it.
Thank you.
a² 5 7012
On Mon, 19 Nov 2007 18:43:58 -0800 (PST) in comp.lang.c++, aaragon
<al************ **@gmail.comwro te,
>Hello, I was wondering if it is possible to forward declare a type definition. If so, what is the way to do it?
Sure, for example,
class foobar;
Of course the type is "incomplete " without the full definition and there
are limits to what you can do with it; you can create pointers to it but
not instances of it.
aaragon wrote:
Hello, I was wondering if it is possible to forward declare a type
definition.
You can forward declare classes.
You cannot, however, forward declare an identifier as a type name to be
defined (e.g., by typedef) later.
If so, what is the way to do it? I found a couple of
messages where they say it's not possible but there must be a way to
do it.
Why?
If you are in a situation where you write code for a type (not necessarily
just a class) yet unknown, consider writing a template.
Best
Kai-Uwe Bux
On Nov 19, 10:16 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote:
aaragon wrote:
Hello, I was wondering if it is possible to forward declare a type
definition.
You can forward declare classes.
You cannot, however, forward declare an identifier as a type name to be
defined (e.g., by typedef) later.
If so, what is the way to do it? I found a couple of
messages where they say it's not possible but there must be a way to
do it.
Why?
If you are in a situation where you write code for a type (not necessarily
just a class) yet unknown, consider writing a template.
Best
Kai-Uwe Bux
I'm using code from a library so I need to create type definitions for
specific types. However, the type definition is defined by using a
templated class that uses it at the same time. Something like this:
typedef Class<MyOwnClas s1, MyOwnClass2Clas sA;
// Then, in the definition of MyOwnClass
template <class SomeClass>
class MyOwnClass {
// uses type definition ClassA
someFun(ClassA& );
};
// and then the actual instantiations of MyOwnClass
typedef MyOwnClass<Some Class1MyOwnClas s1;
typedef MyOwnClass<Some Class2MyOwnClas s2;
so you can see, that the class MyOwnClass depends on types that are
not yet instantiated.
The way I solved this is by moving the typedefinition of MyOwnClass1
and MyOwnClass2 before the first typedef and using a forward
declaration of the template class MyOwnClass. Very messy eh???? It
turns out that this cyclic dependence is because of the use of a
Visitor class that I need to have for MyOwnClass (visitor design
pattern).
a²
aaragon wrote:
On Nov 19, 10:16 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote:
>aaragon wrote:
>>Hello, I was wondering if it is possible to forward declare a type definition.
You can forward declare classes.
You cannot, however, forward declare an identifier as a type name to be defined (e.g., by typedef) later.
>>If so, what is the way to do it? I found a couple of messages where they say it's not possible but there must be a way to do it.
Why?
If you are in a situation where you write code for a type (not necessarily just a class) yet unknown, consider writing a template.
Best
Kai-Uwe Bux
I'm using code from a library so I need to create type definitions for
specific types. However, the type definition is defined by using a
templated class that uses it at the same time. Something like this:
typedef Class<MyOwnClas s1, MyOwnClass2Clas sA;
// Then, in the definition of MyOwnClass
template <class SomeClass>
class MyOwnClass {
// uses type definition ClassA
someFun(ClassA& );
What's wrong with just declaring 'ClassA' a class instead of making
it a typedef? To declare a function that accepts a reference to it
the compiler only needs to know that it's a class (and not an array
or a function, for example).
>
};
// and then the actual instantiations of MyOwnClass
typedef MyOwnClass<Some Class1MyOwnClas s1;
typedef MyOwnClass<Some Class2MyOwnClas s2;
so you can see, that the class MyOwnClass depends on types that are
not yet instantiated.
The way I solved this is by moving the typedefinition of MyOwnClass1
and MyOwnClass2 before the first typedef and using a forward
declaration of the template class MyOwnClass. Very messy eh???? It
turns out that this cyclic dependence is because of the use of a
Visitor class that I need to have for MyOwnClass (visitor design
pattern).
a²
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Nov 20, 11:11 am, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
aaragon wrote:
On Nov 19, 10:16 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote:
aaragon wrote: Hello, I was wondering if it is possible to forward declare a type definition.
You can forward declare classes.
You cannot, however, forward declare an identifier as a type name to
be defined (e.g., by typedef) later.
>If so, what is the way to do it? I found a couple of messages where they say it's not possible but there must be a way to do it.
Why?
If you are in a situation where you write code for a type (not
necessarily just a class) yet unknown, consider writing a template.
Best
Kai-Uwe Bux
I'm using code from a library so I need to create type definitions for
specific types. However, the type definition is defined by using a
templated class that uses it at the same time. Something like this:
typedef Class<MyOwnClas s1, MyOwnClass2Clas sA;
// Then, in the definition of MyOwnClass
template <class SomeClass>
class MyOwnClass {
// uses type definition ClassA
someFun(ClassA& );
What's wrong with just declaring 'ClassA' a class instead of making
it a typedef? To declare a function that accepts a reference to it
the compiler only needs to know that it's a class (and not an array
or a function, for example).
};
// and then the actual instantiations of MyOwnClass
typedef MyOwnClass<Some Class1MyOwnClas s1;
typedef MyOwnClass<Some Class2MyOwnClas s2;
so you can see, that the class MyOwnClass depends on types that are
not yet instantiated.
The way I solved this is by moving the typedefinition of MyOwnClass1
and MyOwnClass2 before the first typedef and using a forward
declaration of the template class MyOwnClass. Very messy eh???? It
turns out that this cyclic dependence is because of the use of a
Visitor class that I need to have for MyOwnClass (visitor design
pattern).
a²
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
ClassA is defined by a library. It is actually a class template, so
the correct type has to be obtained through a type definition. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alexander Grigoriev |
last post by:
Not quite new version of GCC that I have to use, craps with the following
code:
enum E;
enum E { e };
That is, it doesn't accept forward declaration of enum. C++ standard text
doesn't explicitly say about enum's forward declaration, but one example
shows it in 18.2.1, clause 4:
|
by: John Gabriele |
last post by:
I'm hoping someone can please help me remember the C++ rule: When
you're writing a header file for a class (say, some_namespace::Bar),
and that class makes use of another class (some_namespace::Foo),
-------------------------------- snip --------------------------------
#ifndef GUARD_Foo_HPP
#define GUARD_Foo_HPP
namespace some_namespace {
|
by: John Ratliff |
last post by:
I'm having issues with forward declarations and possibly member variables.
Can you declare a member variable and pass it parameters.
class x {
private:
y obj(this);
}
Is that valid? I'm getting a lot of problems, but it may not be due to
|
by: Michael Sgier |
last post by:
Hello
with the original code below I get the error:
"forward declaration of `struct CPlayer'"
class CPlayer; // what does this do? Instantiate the class CPlayer?
// what's a forward declaration?
class CEnemy : public CEntity
{
public:
|
by: Milind |
last post by:
Hi,
I was trying to implement a composition relation, somthing of the
following type:
class A
{
public:
class B
{
| |
by: mark.moore |
last post by:
I know this has been asked before, but I just can't find the answer in
the sea of hits...
How do you forward declare a class that is *not* paramaterized, but is
based on a template class?
Here's what I thought should work, but apparently doesn't:
class Foo;
void f1(Foo* p)
|
by: Steve |
last post by:
Hi,
I always though to return an instance of a class by value, it had to be
defined - i.e. forward declaration isn't good enough?
Consider the following code snippet:
class RGBA;
class Colour
|
by: RedLars |
last post by:
Need some help with a couple of questions. Previously I have seen this
declaration;
struct Student
{
int age;
char name;
};
and this definition of an object;
struct Student stud;
|
by: Jef Driesen |
last post by:
I have the following problem in a C project (but that also needs to
compile with a C++ compiler). I'm using a virtual function table, that
looks like this in the header file:
typedef struct device_t {
const device_backend_t *backend;
...
} device_t;
typedef struct device_backend_t {
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |