473,395 Members | 1,972 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,395 software developers and data experts.

Matching parameter types in overloaded methods

I have a class
Expand|Select|Wrap|Line Numbers
  1. template<class D>
  2. class A {
  3.  
  4. template<XX>
  5. A<D> operator +(const XX& val)  const ....
  6.  
  7. ....etc
  8.  
  9. };
  10.  
Which works fine. I added:
Expand|Select|Wrap|Line Numbers
  1. template<XX>
  2. A<D> operator +(const A<D>& val)  const ....
  3.  
but when I call the method it always matches against the first method where I thought it would choose the more 'specific' method. E.g. If I have
Expand|Select|Wrap|Line Numbers
  1.  A<int> p, q;
  2. cout <<     p + q ;
  3.  
the original method gets called.

Any help/work arounds appreciated.
Oct 17 '07 #1
2 1103
Ganon11
3,652 Expert 2GB
When you are adding another A object. do you ever use the XX type specified in your template? If not, why not just have

Expand|Select|Wrap|Line Numbers
  1. A& operator+(const A& other) const { /*...*/ }
Oct 17 '07 #2
When you are adding another A object. do you ever use the XX type specified in your template? If not, why not just have

Expand|Select|Wrap|Line Numbers
  1. A& operator+(const A& other) const { /*...*/ }
Sorry - that was a typo. What I should have written was:

Expand|Select|Wrap|Line Numbers
  1. template<XX>
  2.       A<D> operator +(const A<XX>& val)  const ....
  3.  
Oct 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Vit | last post by:
Hi. I'd like to pass as a parameter of class method reference to ListControl (ListBox or ComboBox). Here is my call: public DoSomething(ListControl lc){} It's ok with that, but lc does not have...
9
by: Ryan Taylor | last post by:
Hello. I am trying to overload a method so that I have four possible working copies. The only difference between the four methods is what to search by and in what manner to return the results....
21
by: vmsgman | last post by:
Here is a code sample ... int blah = ReadFile( defArray, defFileName, w, h); // Read File Contents into memory array and return for processing public int ReadFile( ref ushort nArray, string...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
2
by: Dave | last post by:
I know in C++ you can create class templates so the data type can be defined during the declaration of an instance of a class. I was trying to do something like that for a VB.NET class cut am not...
5
by: Andreas Mueller | last post by:
Hi All, I have an overloaded generic method anmed "Foo": Class Test Class Xox(Of T) End Class Class Lulli(Of T) Inherits Xox(Of T) End Class
5
by: Martin Jørgensen | last post by:
Hello again, Sorry to bother but I guess my C++ book isn't very good since it obviously contains errors so the program code doesn't work with g++. However I don't understand what the problem...
1
by: Senthryl | last post by:
I just moved from Visual Basic to C++ and recently finished reading my book. However, I'm trying to implement something which has led me to writing the same thing many times, which I've learned is...
2
by: Ole Nielsby | last post by:
First, bear with my xpost. This goes to comp.lang.c++ comp.lang.functional with follow-up to comp.lang.c++ - I want to discuss an aspect of using C++ to implement a functional language, and...
5
by: MathStuf | last post by:
I have a logging function with multiple calling functions that make it more standard with less coding, but I am getting a weird mis-match error that outputs the following: error: call of...
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
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.