Click here to Skip to main content
15,892,737 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Variable Help Pin
borono10-Apr-06 17:30
borono10-Apr-06 17:30 
AnswerRe: Variable Help Pin
Joshua Quick10-Apr-06 17:49
Joshua Quick10-Apr-06 17:49 
GeneralRe: Variable Help Pin
borono11-Apr-06 10:43
borono11-Apr-06 10:43 
GeneralRe: Variable Help Pin
Joshua Quick11-Apr-06 12:05
Joshua Quick11-Apr-06 12:05 
QuestionCTreeCtrl checkboxes Pin
CodeGoose10-Apr-06 11:34
CodeGoose10-Apr-06 11:34 
QuestionOverloads resolution crazyness ? Pin
Marcello10-Apr-06 11:29
Marcello10-Apr-06 11:29 
AnswerRe: Overloads resolution crazyness ? Pin
Ryan Binns10-Apr-06 18:33
Ryan Binns10-Apr-06 18:33 
GeneralRe: Overloads resolution crazyness ? Pin
Marcello10-Apr-06 21:05
Marcello10-Apr-06 21:05 
Thank you very much for the reply.

Please forget about the VCF::String thing. It was a typo on my side.

Here is a code I made for this question ( it compiles
class Cond
{
public:
	typedef std::basic_string<wchar_t> MyString;

	Cond()  { };
	virtual ~Cond(void) { };

	Cond( const Cond& other ) {
		/* simple implementation just for this example */
		*this = other;
	};

	Cond& operator= ( const Cond& other ) {
		return *this;
	};

	// implementation
	bool split( const MyString& s, MyString::size_type* p = NULL );
	bool split( MyString& s, const bool& trim );
};

inline
bool Cond::split( const MyString& s, MyString::size_type* p )
{
	/* simple implementation just for this example */
	return true;
}

inline
bool Cond::split( MyString& s, const bool& trim )
{
	MyString::size_type p;
	//if ( split( const_cast<const MyString&>(s), &p ) ) // this compiles fine
	if ( split( s, &p ) ) // C2666
	{
		s = s.substr( p + 1 );
		return true;
	}
	return false;
}

I get the error message:
1>d:\projs\libraries\vcfex\src\conditions\test.h(51) : error C2666: 'vcfex::Cond::split' : 2 overloads have similar conversions
1> d:\projs\libraries\vcfex\src\conditions\test.h(37): could be 'bool vcfex::Cond::split(vcfex::Cond::MyString &,const bool &)'
1> d:\projs\libraries\vcfex\src\conditions\test.h(36): or 'bool vcfex::Cond::split(const vcfex::Cond::MyString &,stlp_std::basic_string<_CharT,_Traits,_Alloc>::size_type *)'
1> with
1> [
1> _CharT=wchar_t,
1> _Traits=stlp_std::char_traits<wchar_t>,
1> _Alloc=stlp_std::allocator<wchar_t>
1> ]
1> while trying to match the argument list '(vcfex::Cond::MyString, stlp_std::basic_string<_CharT,_Traits,_Alloc>::size_type *)'
1> with
1> [
1> _CharT=wchar_t,
1> _Traits=stlp_std::char_traits<wchar_t>,
1> _Alloc=stlp_std::allocator<wchar_t>
1> ]
1> note: qualification adjustment (const/volatile) may be causing the ambiguity

It puzzles me that the C++ standard ( or is just vc80 ? ) is asking
me to specify const_cast when intuitively the compiler should
resolve the two overloads 'without effort'.


A comment on this after the next point.



I understand what you say at the second point.
I agree but I am really surprised at the same time.
I always considered a const function just as a way to tell the compler that that function is not going to change the 'this' pointer. So I can certainly use it from a non-const function.
This is true. And what you say seems probably true too.
Now I know that this 'const' specifier may affect the overload resolution too.



So at the end it seems that the standard C++ is treating a difference between
const and non-const at the same level as a difference between types completely
unrelated
. This, even when the the const specifier is just there to tell that
what is specified as const will not be changed by the function using that instance
( the 'this' or the MyString instance )

At this point I wonder if this is one limit of the C++ ( IMHO of course ),
or if it really necessary to have it like that.



Cheers,
Marcello
GeneralRe: Overloads resolution crazyness ? Pin
Ryan Binns10-Apr-06 22:50
Ryan Binns10-Apr-06 22:50 
GeneralQuick question about IEEE floating points Pin
Jörgen Sigvardsson10-Apr-06 10:39
Jörgen Sigvardsson10-Apr-06 10:39 
GeneralRe: Quick question about IEEE floating points Pin
cmk10-Apr-06 15:04
cmk10-Apr-06 15:04 
QuestionLogo on a dialog app Pin
LCI10-Apr-06 9:59
LCI10-Apr-06 9:59 
QuestionRe: Logo on a dialog app Pin
David Crow10-Apr-06 10:03
David Crow10-Apr-06 10:03 
AnswerRe: Logo on a dialog app Pin
LCI10-Apr-06 10:20
LCI10-Apr-06 10:20 
GeneralRe: Logo on a dialog app Pin
Laxman Auti10-Apr-06 17:55
Laxman Auti10-Apr-06 17:55 
QuestionRe: Logo on a dialog app Pin
David Crow11-Apr-06 2:40
David Crow11-Apr-06 2:40 
AnswerLogo on a dialog app Pin
_AnsHUMAN_ 10-Apr-06 18:15
_AnsHUMAN_ 10-Apr-06 18:15 
AnswerRe: Logo on a dialog app Pin
Ryan Binns10-Apr-06 18:37
Ryan Binns10-Apr-06 18:37 
AnswerRe: Logo on a dialog app Pin
Krishnatv10-Apr-06 19:22
Krishnatv10-Apr-06 19:22 
AnswerRe: Logo on a dialog app Pin
Ștefan-Mihai MOGA11-Apr-06 0:09
professionalȘtefan-Mihai MOGA11-Apr-06 0:09 
Questionwindow update Pin
pnpfriend10-Apr-06 7:27
pnpfriend10-Apr-06 7:27 
AnswerRe: window update Pin
Ravi Bhavnani10-Apr-06 7:41
professionalRavi Bhavnani10-Apr-06 7:41 
QuestionRe: window update Pin
David Crow10-Apr-06 8:19
David Crow10-Apr-06 8:19 
AnswerRe: window update Pin
pnpfriend10-Apr-06 8:56
pnpfriend10-Apr-06 8:56 
GeneralRe: window update Pin
David Crow10-Apr-06 9:04
David Crow10-Apr-06 9:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.