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

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 9026
"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>(const 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>(const 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*******@mariani.ws> wrote in message
news:c1********@dispatch.concentric.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>(const 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
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
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
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...
11
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
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...
3
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: ...
3
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...
8
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...

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.