Connecting Tech Pros Worldwide Forums | Help | Site Map

Circular declarations

Armin Zingler
Guest
 
Posts: n/a
#1: Nov 19 '08
Hi,

I'm using VC++ 2008 Express.

I have a managed interface. One of it's member uses a type that is declared
later in the same file. The type implements the interface declared before.
So, I have circular relations between the two declarations.
Question: How do I have to forward-declare the struct? (C++ is still not
clever enough to see the declaration below.)

public interface class IMatrixSource
{
Matrix GetMatrix(); // error: unknown type
};


public value struct Matrix: IMatrixSource
{
public:
//.....
private:
Matrix GetValue() = IMatrixSource::GetValue;
};


If I write "ref struct Matrix;" above the interface declaration, the
compiler says C3816, "'struct Matrix' was previously declared or defined
with a different managed modifier" at the later declaration. What is the
correct syntax?


Armin




David Wilkinson
Guest
 
Posts: n/a
#2: Nov 19 '08

re: Circular declarations


Armin Zingler wrote:
Quote:
Hi,
>
I'm using VC++ 2008 Express.
>
I have a managed interface. One of it's member uses a type that is declared
later in the same file. The type implements the interface declared before.
So, I have circular relations between the two declarations.
Question: How do I have to forward-declare the struct? (C++ is still not
clever enough to see the declaration below.)
>
public interface class IMatrixSource
{
Matrix GetMatrix(); // error: unknown type
};
>
>
public value struct Matrix: IMatrixSource
{
public:
//.....
private:
Matrix GetValue() = IMatrixSource::GetValue;
};
>
>
If I write "ref struct Matrix;" above the interface declaration, the
compiler says C3816, "'struct Matrix' was previously declared or defined
with a different managed modifier" at the later declaration. What is the
correct syntax?
Armin:

If Matrix is a value struct, it might be a good idea to forward declare it as a
value struct.

--
David Wilkinson
Visual C++ MVP
Armin Zingler
Guest
 
Posts: n/a
#3: Nov 19 '08

re: Circular declarations


"David Wilkinson" <no-reply@effisols.comschrieb
Quote:
Quote:
>If I write "ref struct Matrix;" above the interface declaration, the
>compiler says C3816, "'struct Matrix' was previously declared or defined
>with a different managed modifier" at the later declaration. What is the
>correct syntax?
>
Armin:
>
If Matrix is a value struct, it might be a good idea to forward declare it
as a value struct.
OMG, :-/ I *copied* the declaration! Don't know how this could happen.
Thanks, you're right. I'm really ashamed of this; it's so obvious.

Thanks again for your quick reply.


Armin

Closed Thread