473,569 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

forward declaration of a structure nested in a class

Hi,

I would like to make a forward declaration of a strcuture nested in a class.
I have

file A.h
class A
{
public:
struct B
{
};
};

file C.h
class C
{
public:
static doIt(const A::B& object);
};

I tried :
struct A::B;
but it doesn't work ( MSVCPP 6.0 last SP )

Is it a way to do that ?

thanks in advance,

Stephane Routelous
Jul 22 '05 #1
5 9055
"Stephane Routelous" <no****@nowhere .com> wrote in message
news:c1******** **@dns3.cae.ca
Hi,

I would like to make a forward declaration of a strcuture nested in a
class. I have

file A.h
class A
{
public:
struct B
{
};
};

file C.h
class C
{
public:
static doIt(const A::B& object);
};

I tried :
struct A::B;
but it doesn't work ( MSVCPP 6.0 last SP )

Is it a way to do that ?


No, the only type of forward declaration allowed for a nested class is one
inside the enclosing class, e.g.,

class Outer
{
// forward declaration of inner class
class Inner;
// other stuff
}

// full declaration of inner class
class Outer::Inner
{
// Inner stuff
};
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #2
Stephane Routelous wrote:
Hi,

I would like to make a forward declaration of a strcuture nested in a class.
I have

file A.h
class A
{
public:
struct B
{
};
};

file C.h
class C
{
public:
static doIt(const A::B& object);
};

I tried :
struct A::B;
but it doesn't work ( MSVCPP 6.0 last SP )

Is it a way to do that ?


No.

You might be able to use a template, i.e.:

class A;

class C
{
public:
template <class tA>
static int doIt(const typename tA::B & object);
};
class A
{
public:
struct B
{
};
};
template <>
int C::doIt<A>(cons t A::B & object)
{
}
oops now I'm not sure you can specialize outside of the class
declaration - this one is new to me.

Jul 22 '05 #3
Gianni Mariani wrote:
Stephane Routelous wrote:

.... Sorry I'd suggest you do it this way below - that way you don't need
to specify the <A> in doit<A>.
class A;

class C
{
public:
template <class tA_B>
static int doIt(const tA_B & object);
};
class A
{
public:
struct B
{
};
};
template <>
int C::doIt<A::B>(c onst A::B & object)
{
return 0;
}
int main()
{
A::B x;

C::doIt( x );
}


oops now I'm not sure you can specialize outside of the class
declaration - this one is new to me.


I'm still not sure this is legal but g++ (3.4prerel) works fine with it.

Jul 22 '05 #4
I tried that, but I got a beautiful internal compiler error with vc++6.0

Thanks,

Stephane

"Gianni Mariani" <gi*******@mari ani.ws> wrote in message
news:c1******** @dispatch.conce ntric.net...
Gianni Mariani wrote:
Stephane Routelous wrote:


... Sorry I'd suggest you do it this way below - that way you don't need
to specify the <A> in doit<A>.
class A;

class C
{
public:
template <class tA_B>
static int doIt(const tA_B & object);
};
class A
{
public:
struct B
{
};
};
template <>
int C::doIt<A::B>(c onst A::B & object)
{
return 0;
}
int main()
{
A::B x;

C::doIt( x );
}

>
> oops now I'm not sure you can specialize outside of the class
> declaration - this one is new to me.
>


I'm still not sure this is legal but g++ (3.4prerel) works fine with it.

Jul 22 '05 #5
Stephane Routelous wrote:
I tried that, but I got a beautiful internal compiler error with vc++6.0


vc++6.0 is too old. Time to upgrade to GCC ... :-)
Jul 22 '05 #6

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

Similar topics

3
5453
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
2
2791
by: Jiri Palecek | last post by:
Hi How can I (can I?) forward declare a nested class without having to define the class it is nested in? Like this class A; class A::B; void f(A::B*); Thanks in advance
7
2858
by: Lynn | last post by:
I am rewriting some memory management code and I need to have a forward declaration of a data structure. I am not converting this data structure into a class (yet). How do I generate a forward reference of a data structure ? For a class, I just say: class SomeClass; "struct SomeStructure;" does not work to forward declare the data...
11
2419
by: aleko | last post by:
This applies equally to function prototypes. Why do we have to tell the compiler twice? Other modern compiled languages don't have this requirement. Just curious, Aleko
2
1684
by: Dylan | last post by:
If I have a class with a nested struct such as class MyClass { class NestedClass {}; }; Is it possible to forward declare the nested class in a separate header file? I want to do something like the following but my compiler
3
4628
by: Torsten Mueller | last post by:
I have sources containing lots of namespaces (even nested ...) I'm porting these classes to gcc 3.3.2. At the moment I get several error messages like this: ../../src/libFormalValidation/ErrorCache.h:20: error: forward declaration of `struct Support::CErrorInfo' The code at this place is:
3
4096
by: DhaneshNair | last post by:
Hi all, I hav a file which is actually linkage file (used as an reference interface between c and c++ files). And this file has got two structures in it .. When i include this file directly i dont have any issues. but according to some norms in the review I am not supposed to use this file direclty in the header file .. but its fine if i...
8
28439
by: Mohammad Omer Nasir | last post by:
Hi, i made a structure in header file "commonstructs.h" is: typedef struct A { int i; A( ) {
11
8296
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 {
0
7930
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, 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. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
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 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...
0
6290
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
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
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.