[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Default parameters - problems
From: |
anitha boyapati |
Subject: |
Default parameters - problems |
Date: |
Fri, 15 Jun 2007 21:20:45 +0530 |
Hello,
I faced some compilation errors with a small test case. I sort of
accidentally hit it.
and since then I am trying to analyse the cause with no use. Please
look at the code
below:
File - test.h
#include <iostream>
using namespace std;
class test {
public :
test() { };
void func1(string str1, bool i = false, int id = -1);
//overload func1
void func1(string str1, string str2, bool i = false);
};
File - test.cc
#include "test.h"
void test::func1(string str1, bool i, int id ) {
}
void test::func1(string str1, string str2, bool i ) {
}
int main() {
test *t = new test();
t->func1("hello", "world", false); // call func1
}
-----------------------------------------------------------------------------------------------------------
E:\test\g++ test.cc
test.cc: In function `int main()':
test.cc:11: error: call of overloaded `func1(const char[6], const
char[6], bool)' is ambiguous
test.cc:3: note: candidates are: void test::func1(std::string, bool, int)
test.cc:6: note: void test::func1(std::string, std::string, bool)
Why is this not compiling ? Can somebody explain what is going on here ?
Why is it not directly going to overloaded func1 () - declared second. ?
Explanation is greatly welcome ( I would be much more relieved than
hoping and searching in bugzilla)
Obviously removing the third parameter of type int from
void func1(string str1, bool i = false, int id = -1) succeeds in compiling.
My version : g++ 3.4.4 (cygming special)
E:test> g++ -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with:
/usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose
--prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls
--without-included-gettext --enable-version-specific-runtime-libs
--without-x --enable-libgcj --disable-java-awt --with-system-zlib
--enable-interpreter --disable-libgcj-debug --enable-threads=posix
--enable-java-gc=boehm --disable-win32-registry
--enable-sjlj-exceptions --enable-hash-synchronization
--enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
--
Anitha Boyapati
- Default parameters - problems,
anitha boyapati <=