Forward declaration with value class

J

Jerome

Hi all,

I'm trying to use forward declaration with value class but I don't succeed
in compiling my (quite simple) sample code.
This is my code I'm trying to compile (Visual Studio 2003)

namespace managedDll
{
public __value class VecDouble;
public __value class VecFloat
{
public:
void SetValue(VecDouble vec)

{
// TODO
}

};

public __value class VecDouble
{

public:
void SetValue(VecFloat vec)

{
// TODO
}

};
}

I've got the following error when compiling:
error C2027: use of undefined type 'managedDll::VecDouble'

Every think work fine if my SetValues methods have the signature (Vec(Double
| Float) &vec).
The problem is that putting a '&' is not logical because I want to call
methods from C# code and with this signature I should write the following
code

VecDouble vec = new VecDouble();
vecFloat.SetValue(ref vec);

Instead I want to call my methods in this way:
vecFloat.SetValue(new VecDouble())
The first solution is not acceptable !.

Does anyone encounter the same problem ?

Great thanks.
Jerome
 
E

Eckart Haug

Forward declaration by definition only works with pointers (VecDouble* vec) and refenences (VecDouble& vec).
This is because in this cases the parameter is just an address. If you pass an object by value, the compiler
creates a copy of the object on the stack - and therefore needs all the information of the object, e.g. how
many bytes it occupies, whether it has a copy constructor and so on.
 
J

Jerome

I know that ... and that's why I think there's a problem with managed C++
language.
It's not acceptable that a method you think taking a parameter as 'In' must
be signed by 'ref'
Of course the problem does not exists with reference class.

I'm still dreaming of a magic attribute or magic compilation option ... who
knows ? ... certainly Microsoft developpers ... Anyone from Microsoft Visual
Studio team to solve my issue or explain why it can't be possible ???

Eckart Haug said:
Forward declaration by definition only works with pointers (VecDouble*
vec) and refenences (VecDouble& vec).
This is because in this cases the parameter is just an address. If you
pass an object by value, the compiler
creates a copy of the object on the stack - and therefore needs all the
information of the object, e.g. how
 
J

James Park

How about something like this:
namespace managedDll
{
public __value class VecDouble;
public __value class VecFloat
{
public:
void SetValue(VecDouble vec);
};

public __value class VecDouble
{
public:
void SetValue(VecFloat vec)
{
// TODO
}
};

void VecFloat::SetValue(VecDouble vec)
{
// TODO
}
}
 

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

Top