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

weird C++ "ambiguous call to overloaded function"

hiya, i'm having this weird error on my project. As far as I know "ambiguous call to overloaded function" should only occur when the compiler must choose from several methods, but here i don't think it's the case. I've got the following class:


Expand|Select|Wrap|Line Numbers
  1. class item
  2. {
  3. public:
  4.     item(string id_,string datatype_);
  5.     //item(string id_,string datatype_,int periodo_);
  6.     //item(string id_,string datatype_,string headerfile_);
  7.     //item(string id_, string datatype_, int periodo_=1, string headerfile_="");
  8.     //item(const item& it);
  9.  
  10.     void set_id(string id_);
  11.     void set_datatype(string datatype_);
  12.     void set_periodo(int periodo_);
  13.     void set_headerfile(string headerfile_);
  14.  
  15.     string get_id();
  16.     string get_datatype();
  17.     int get_periodo();    
  18.     string get_headerfile();
  19.  
  20.     item& operator=(const item& var);
  21. //    item operator*();
  22.     virtual ~item();
  23.  
  24. public:
  25.     string id;
  26.     string datatype;
  27.     int periodo;
  28.     string headerfile;
  29. };
  30.  
  31.  
  32. (most of the methods are commente because I was going crazy trying to solve this)
  33.  
  34. the main is like this (just for testing):
  35.  
  36. int main()
  37. {
  38.     item var3("string1", "string2");
  39.  
  40.     return 0;
  41. }
  42.  

all the other commented methods work, but this constructor raises the error,

any help is much appreciated

thanks in advance.
May 9 '07 #1
6 3797
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. item(string id_,string datatype_);
  2. item(string id_, string datatype_, int periodo_=1, string headerfile_="");
Those are the two functions that are ambiguous. Which function to use when
someone does this?
Expand|Select|Wrap|Line Numbers
  1. item("foo", "bar");
kind regards,

Jos
May 9 '07 #2
Those are the two functions that are ambiguous. Which function to use when
someone does this?
Expand|Select|Wrap|Line Numbers
  1. item("foo", "bar");
kind regards,

Jos

that should summon the 1st function:

Expand|Select|Wrap|Line Numbers
  1. item(string id_,string datatype_);
May 9 '07 #3
JosAH
11,448 Expert 8TB
that should summon the 1st function:

Expand|Select|Wrap|Line Numbers
  1. item(string id_,string datatype_);
Nope, the other two parameters are optional (you supplied default values for them).

kind regards,

Jos
May 9 '07 #4
Nope, the other two parameters are optional (you supplied default values for them).

kind regards,

Jos
hm... but even either function, the problem persists...

item var("abc", "def");

should summon both

item(string id_,string datatype_);
and
item(string id_, string datatype_, int periodo_=1, string headerfile_="");

thus creating ambiguity. so if either function was removed, visual studio should call the correct function, right? but the poroblem persists.. =(
May 9 '07 #5
Ganon11
3,652 Expert 2GB
Maybe you could have a single constructor giving default values to all parameters? On the one hand, you wouldn't be able to use the constructor with 3 strings, but on the other, there would be no ambiguity.
May 9 '07 #6
AdrianH
1,251 Expert 1GB
hm... but even either function, the problem persists...

item var("abc", "def");

should summon both

item(string id_,string datatype_);
and
item(string id_, string datatype_, int periodo_=1, string headerfile_="");

thus creating ambiguity. so if either function was removed, visual studio should call the correct function, right? but the poroblem persists.. =(
What Jos stated should be correct. So post the error messages and the lines that they refer to with some context around them. That way we can determine what the problem is.


Adrian
May 9 '07 #7

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

Similar topics

3
by: ¤ Alias | last post by:
I have a function named getID3info (lvwDiscInfo.SelectedItem). What is the difference between getID3info (lvwDiscInfo.SelectedItem) and Call getID3info(lvwDiscInfo.SelectedItem) ?
12
by: Steffen | last post by:
Hi, I stumbled across the following error foo.cc: In function `int main()': foo.cc:15: error: no matching function for call to `Bar::foo(int)' foo.cc:9: error: candidates are: void...
7
by: Denis Samoilov | last post by:
We have a namespace N which includes enumeration ENUM1 and a class C with property C.Enum1, e.g. namespace N { public enum ENUM1{}; public class C { public ENUM1 Enum1 { get{} set{}
4
by: Gary Brown | last post by:
Hi, Why are fn(object parameters) and fn(params object parameters)
2
by: John Goche | last post by:
Hello, Could anyone please provide with some information on the C++ overloaded cast operator and in which circumstances this might be useful? I have consulted several references but found no...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
3
by: kartik369 | last post by:
hi while compiling my code im getting these errors: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinBase.h(4729): error C2872: 'FILETIME' : ambiguous symbol ...
2
by: Michael Scott | last post by:
This is driving me nuts. Can anyone help? I have a program which searches for and analyses Access databases across a corporate network. At one point in the code I am looping quickly through all...
1
by: John Kotuby | last post by:
Hi all. I am using VS 2005 and VB.NET. Lately as my Web Application is getting larger, I have been getting strange compiler messages like the following: --------------------------- Compiler...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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: 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?
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
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,...
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...

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.