473,385 Members | 1,983 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.

C# overloaded operators not working from Managed C++

I have some classes written in C# that work fine from Managed C++ and
Visual Basic .NET in all areas except for operator overloading (+, -,
*). I fully understand that I need to offer a secondary method for
Visual Basic to use as it does not support operator overloading.
However I would expect it to work in C++
Instead I get the following error on compilation:

E:\C#>CL democpp.cpp /clr
Microsoft (R) C/C++ Standard Compiler Version 13.00.9466 for .NET
Framework
Copyright (C) Microsoft Corporation 1984-2001. All rights reserved.

democpp.cpp
democpp.cpp(21) : error C2296: '*' : illegal, left operand has type
'Modules::cModule_256K __gc *'
democpp.cpp(21) : error C2297: '*' : illegal, right operand has type
'Modules::cModule_256K __gc *'

I reference the C# DLLs with these lines:
#using <encModules.dll>
using namespace Modules;

Any help on this subject much appreciated!

Nick
Nov 16 '05 #1
1 2916
dbwNick wrote:
I have some classes written in C# that work fine from Managed C++ and
Visual Basic .NET in all areas except for operator overloading (+, -,
*). I fully understand that I need to offer a secondary method for
Visual Basic to use as it does not support operator overloading.
However I would expect it to work in C++


Unfortunately, operator overloading for managed types is not easily
accessible in C++. This is because __gc class types can only be created as
__gc pointers, and operator overloading does not work on pointers. You can
bind an instance to a __gc& and then try calling the operator on the
reference. A better solution is simply to call the op_* function directly
(i.e. op_Addition, op_Subtraction, etc.)

I have to admit, this is really frustrating. We're very focused on improving
this in the next release of Visual C++. I'm sorry that we don't have
anything better right now.

Cheerio!

--
Brandon Bray Visual C++ Compiler
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #2

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

Similar topics

5
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: ...
20
by: Brad Eck | last post by:
"The only operators that cannot be overloaded are :: (scope resolution), . (member selection), and .* (member selection through pointer to function). Quoting from Stroustrup's 3rd edition of _The...
4
by: masood.iqbal | last post by:
Please help me with this doubt that I have regarding overloaded operators. Sometimes they are member functions and sometimes they are friends (e.g. see the code snippet from Stroustrup, Second...
10
by: maadhuu | last post by:
hi i wasnt to know the answer for the following. now ,u can overload all the operators which are basically determined at runtime (coz' of whch operators like sizeof())cannot be overloaded. now...
1
by: Alex Zhitlenok | last post by:
Hi, My question is how to resolve in C# ambiguous overloaded operators? Let say, I have two unrelated classes A and B, each one implements overloaded operator + with the first parameter of type...
3
by: cybertof | last post by:
Hello, Is it possible in C# to have 2 overloaded functions with - same names - same parameters - different return type values If no, is it possible in another language ?
0
by: Skute | last post by:
Hi, is it possible to create custom overloaded operators in managed C++? The reason i ask is because in VC6, you can do this operator const char* () { return this->m_pszTheString; Which...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
3
by: simbasaurus | last post by:
Hello! I am working on a really big project, in which the global new and delete operators can be overloaded, by including the file "overloadedops.h". The graphical interface was written using...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.