473,789 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Avoiding ambiguities

MiG
Hello,

I have the following operators declared in a class:

// Provides R/W direct access to the matrix.
__forceinline const T& operator[](USHORT ndx) const throw()
{ _ASSERT(ndx < 16); return(_mx[ndx]); }
__forceinline T& operator[](USHORT ndx) throw()
{ _ASSERT(ndx < 16); return(_mx[ndx]); }

// Returns pointer to matrix data.
__forceinline operator const T*() const throw()
{ return(_mx); }
__forceinline operator T*() throw()
{ return(_mx); }
When I compile it I get the following errors:

error C2666: 'Matrix4<T>::op erator []' : 4 overloads have similar
conversions
with
[
T=float
]
d:\~alibrary\pr j\cpp\xgl\0.1a1 \inc\primitives .hpp(1515): could
be 'float &Matrix4<T>::op erator [](USHORT) throw()'
with
[
T=float
]
d:\~alibrary\pr j\cpp\xgl\0.1a1 \inc\primitives .hpp(1513): or
'const float &Matrix4<T>::op erator [](USHORT) throw() const'
with
[
T=float
]
or 'built-in C++ operator[(const float *, int)'
or 'built-in C++ operator[(float *, int)'
Is there a way of avoiding these errors without having to create a
method for, say, replacing the functionality of the T* operators?
Aug 1 '07 #1
2 1546
MiG wrote:
I have the following operators declared in a class:

// Provides R/W direct access to the matrix.
__forceinline const T& operator[](USHORT ndx) const throw()
{ _ASSERT(ndx < 16); return(_mx[ndx]); }
__forceinline T& operator[](USHORT ndx) throw()
{ _ASSERT(ndx < 16); return(_mx[ndx]); }

// Returns pointer to matrix data.
__forceinline operator const T*() const throw()
{ return(_mx); }
__forceinline operator T*() throw()
{ return(_mx); }
Please, when posting here, try to remove all compiler-specific
junk, like that ___blah nonsense. Your code is not easy to read
with all that crud in it.
When I compile it I get the following errors:

error C2666: 'Matrix4<T>::op erator []' : 4 overloads have similar
conversions
with
[
T=float
]
d:\~alibrary\pr j\cpp\xgl\0.1a1 \inc\primitives .hpp(1515): could
be 'float &Matrix4<T>::op erator [](USHORT) throw()'
with
[
T=float
]
d:\~alibrary\pr j\cpp\xgl\0.1a1 \inc\primitives .hpp(1513): or
'const float &Matrix4<T>::op erator [](USHORT) throw() const'
with
[
T=float
]
or 'built-in C++ operator[(const float *, int)'
or 'built-in C++ operator[(float *, int)'
Is there a way of avoiding these errors without having to create a
method for, say, replacing the functionality of the T* operators?
Well, just don't provide the operator T*. Why do you think you need
it in the first place?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '07 #2
MiG
Victor Bazarov wrote:
MiG wrote:
>I have the following operators declared in a class:

// Provides R/W direct access to the matrix.
__forceinlin e const T& operator[](USHORT ndx) const throw()
{ _ASSERT(ndx < 16); return(_mx[ndx]); }
__forceinlin e T& operator[](USHORT ndx) throw()
{ _ASSERT(ndx < 16); return(_mx[ndx]); }

// Returns pointer to matrix data.
__forceinlin e operator const T*() const throw()
{ return(_mx); }
__forceinlin e operator T*() throw()
{ return(_mx); }

Please, when posting here, try to remove all compiler-specific
junk, like that ___blah nonsense. Your code is not easy to read
with all that crud in it.
>When I compile it I get the following errors:

error C2666: 'Matrix4<T>::op erator []' : 4 overloads have similar
conversions
with
[
T=float
]
d:\~alibrary\pr j\cpp\xgl\0.1a1 \inc\primitives .hpp(1515): could
be 'float &Matrix4<T>::op erator [](USHORT) throw()'
with
[
T=float
]
d:\~alibrary\pr j\cpp\xgl\0.1a1 \inc\primitives .hpp(1513): or
'const float &Matrix4<T>::op erator [](USHORT) throw() const'
with
[
T=float
]
or 'built-in C++ operator[(const float *, int)'
or 'built-in C++ operator[(float *, int)'
Is there a way of avoiding these errors without having to create a
method for, say, replacing the functionality of the T* operators?

Well, just don't provide the operator T*. Why do you think you need
it in the first place?

V
Alright V, thanks for that. I was really hoping there was a way to keep
the two operators. Not a problem though; I'll just remove the T*s...

Again, thanks V.
Aug 1 '07 #3

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

Similar topics

8
7651
by: Dan | last post by:
Quick question about passing variables to subs to reduce the need for publicly declared variables in VB6. If I have an event sub (MouseDown) that runs a few lines of code, how can I use a variable in that sub without making it global? I tried adding the variable to the arguments of the sub, but VB doesn't seem to like anything other than the predescribed format of the event. So, for example, given the MouseDown event: Private Sub...
10
2892
by: Nick Craig-Wood | last post by:
I'm trying to avoid using shell metacharacters in os.popen in a portable fashion. os.popen() only seems to take a string as the command which would need tricky quoting. os.popen2() can take a string or a list - the relevant code in Unix python (in popen2.py) being... def _run_child(self, cmd):
6
3941
by: Peter Ammon | last post by:
Let's say I need to swap two int values frequently. I would write a macro: #define swap(int a, int b) \ do { \ int temp = (a); \ (a) = (b); \ (b) = temp; \ } while (0)
2
1212
by: NH | last post by:
Hi, I have two dropdown lists in a web form. When you choose an entry in the first list the code retrieves records from the database and displays them in the second dropdownlist. Is there a way of avoiding a postback with this by maybe retrieving all the data at the start and then filtering what should be displayed on the second dropdown list on the client side?
4
3641
by: Frank-René Schäfer | last post by:
-- A class needs to have N members according to N types mentioned in a typelist (possibly with one type occuring more than once). -- The classes should be generated **avoiding** multiple inheritance (avoiding prosperation of virtual func tables). -- At the same time, a class taking N types shall contain a virtual member function that calls a function according to the number of arguments That means, something like:
2
3650
by: manuelg | last post by:
Here is a code fragment, where I am trying to copy a file, avoiding overwrites and race conditions. The filename gets a '02','03','04' etc appended to the end if a file with that name already exists. I know the writing of the single space is overkill, but I am surprised I cannot find an example of this floating around the web and newsgroups my understanding of 'os.open' and 'os.fdopen' is minimal ## start fragment
11
1449
by: Bob Nelson | last post by:
It's been a long time since I've posed a query here on c.l.c. My work environment evolved to primarily C++ and Perl with very little C, so I've forgotten quite a lot over time. This revisits the much-discussed topic of decrementing a pointer to the non-existent location before the start of an array. I've been re-reading K.N. King's ``C Programming: A Modern Approach'' and came across ``reverse2.c'' on page 228, which raised a red flag. I...
27
2879
by: galt_57 | last post by:
I need to do just a few multiplies of long integers and have a divide by ten. Can I avoid using floats? Can I use two longs as a 64 bit value somehow? Thanks.
8
2200
by: junky_fellow | last post by:
Hi, Sorry, for asking similar questions again and again. 1) I want to know how should we reslove the ambiguities in a c expression ? Should we use precedence table as mentioned in K&R book or should we refer to the ANSI C grammar ? 2) As told by many people in this newsgroup that ANSI C grammar does
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.