Connecting Tech Pros Worldwide Help | Site Map

Circular declarations

  #1  
Old November 19th, 2008, 01:35 PM
Armin Zingler
Guest
 
Posts: n/a
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

  #2  
Old November 19th, 2008, 01:45 PM
David Wilkinson
Guest
 
Posts: n/a

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
  #3  
Old November 19th, 2008, 01:55 PM
Armin Zingler
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
solving circular dependencies with class only delcared in .h Mosfet answers 6 October 31st, 2008 03:45 PM
A dilemna with circular reference of headers file JCB answers 3 November 13th, 2005 03:28 AM
Semi-circular definitions (plus circular references) Kiuhnm answers 16 July 23rd, 2005 12:18 AM
circular dependencies, unrecognized base types, oh-my crichmon answers 3 July 22nd, 2005 04:23 PM