uses managed c++ classes in c#

T

Thomas

I can't call a method with managed(__gc) c++ class arguments.
e.g.
c++:
public __gc class Point { ... }

public __gc class Line
{
Line(Point *p0, Point *p1) { ... }
}

c#
namespace MyName
{
...
Point p0 = new Point(1,1);
Point p1 = new Point(2,2);
-> Line line = new Line(p0, p1);
...

I get following compiler error at the marked -> line:
error CS1502 ...
error CS1503 Argument1 can't be converted from MyName.Point to Point

Anybody know, how can I call the 'Line constructor' with 'Point' arguments?

Thanks in advance
Thomas
 
W

Willy Denoyette [MVP]

Hard to say if you don't post the whole code, but I guess you have defined
Point in the MyName namespace too.

Following works for me:

// File: point.cpp
// Compile with : CL /clr /LD point.cpp
public __gc class Point
{
public:
Point(int p1, int p2)
{
v1 = p1;
v2 = p2;
}
private:
int v1;
int v2;

};


public __gc class Line
{

public:
Line(Point* p1, Point* p2)
{}



// File: test.cs
// Compiler command : csc /r:point.dll test.cs
using System;
namespace MyName
{
class Tester
{
static void Main()
{
Point p1, p2;
p1 = new Point(1,1);
p2 = new Point(2,2);
Line l = new Line(p1, p2);
}
}
}


Willy.
 
T

thomas

Your are right. I created a second Point definition in the namespace MyName.
Sorry and thanks
Thomas
 

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