I create a operator + declared in C# to be used in C++

  • Thread starter Thread starter Olaf Baeyens
  • Start date Start date
O

Olaf Baeyens

I create a operator + in C#

public static HistogramBuffer operator+(HistogramBuffer
aHistogramBuffer1, HistogramBuffer aHistogramBuffer2) {
HistogramBuffer Tmp=new HistogramBuffer(aHistogramBuffer1);
for (int iX=0; iX<Tmp.NrOfValues; iX++) {
Tmp[iX]=Tmp[iX]+aHistogramBuffer2[iX];
}
return Tmp;
}

Now in C# I can do this:

HistogramBuffer Test1=new HistogramBuffer();
HistogramBuffer Test2=new HistogramBuffer();

Test2=Test2+Test1;

But if I do this In C++

HistogramBuffer __gc *Test1=__gc new HistogramBuffer();
HistogramBuffer __gc *Test2=__gc new HistogramBuffer();

Test2=Test2+Test1;

Then I get this error: "error C2845: '+' : cannot perform pointer arithmetic
on __gc pointer....."
Any idea how to fix this?
 
--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Olaf Baeyens said:
I create a operator + in C#

public static HistogramBuffer operator+(HistogramBuffer
aHistogramBuffer1, HistogramBuffer aHistogramBuffer2) {
HistogramBuffer Tmp=new HistogramBuffer(aHistogramBuffer1);
for (int iX=0; iX<Tmp.NrOfValues; iX++) {
Tmp[iX]=Tmp[iX]+aHistogramBuffer2[iX];
}
return Tmp;
}

Now in C# I can do this:

HistogramBuffer Test1=new HistogramBuffer();
HistogramBuffer Test2=new HistogramBuffer();

Test2=Test2+Test1;

But if I do this In C++

HistogramBuffer __gc *Test1=__gc new HistogramBuffer();
HistogramBuffer __gc *Test2=__gc new HistogramBuffer();

Test2=Test2+Test1;

Then I get this error: "error C2845: '+' : cannot perform pointer arithmetic
on __gc pointer....."
Any idea how to fix this?

since Test1 and Test2 are not HistogramBuffers but pointers to a
HistogramBuffer you have to write something like:

Test2 = &((*Test2)+(*Test1));

You dereference both Test2 and Test1, add them together and get the address
of the result.

But Iam not sure weather this will work :)
 
since Test1 and Test2 are not HistogramBuffers but pointers to a
HistogramBuffer you have to write something like:

Test2 = &((*Test2)+(*Test1));

You dereference both Test2 and Test1, add them together and get the address
of the result.

But Iam not sure weather this will work :)
It doesn't compile, I also tried many variations with typecasting.
Anyway it looks very ugly if I have to do that this way.

So for the C++ I added a Add()
Like this:
Test2->Add(Test1);

While in C# I use
Test2=Test2+Test1;


Thanks for the reply. :-)
 
This works in VC 2005. Using * for __gc class instances made it almost
semantically impossible to support this in the MC++ 1.x syntax.

Ronald
 
Back
Top