forward declaration of a structure nested in a class

S

Stephane Routelous

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
 
J

John Carson

Stephane Routelous said:
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
};
 
G

Gianni Mariani

Stephane said:
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.
 
G

Gianni Mariani

Gianni said:
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.
 
S

Stephane Routelous

I tried that, but I got a beautiful internal compiler error with vc++6.0

Thanks,

Stephane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top