473,385 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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?

--
http://www.skyscan.be
Nov 17 '05 #1
3 874


--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"Olaf Baeyens" <ol**********@skyscan.be> schrieb im Newsbeitrag
news:41***********************@news.skynet.be...
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?

--
http://www.skyscan.be


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 :)
Nov 17 '05 #2
> 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. :-)

--
http://www.skyscan.be
Nov 17 '05 #3
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

"Olaf Baeyens" <ol**********@skyscan.be> wrote in message
news:41***********************@news.skynet.be...
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. :-)

--
http://www.skyscan.be

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If...
10
by: Piotr Wyderski | last post by:
Hello, is it possible to reuse a friend operator which is defined inside a class? I'd like to obtain the following behaviour: class integer { integer operator +(signed long int v) const...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: Peng Yu | last post by:
Hi, In the following code, the 'copy' member function works. But the '=' operator does not work. Can somebody let me know why a member function is different from an operator. Thanks, Peng ...
0
by: dbsog7777 | last post by:
I was trying to use the sample code below, but I encountered two errors: Application.DoEvents() and AutoText(entry). I am not sure how to correct the errors. I trying to use the sample code to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.