Re: string cast
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Mon, 17 Sep 2007 08:24:45 -0400
"Alan Leng" <alan.lenng@xxxxxxxxx> wrote in message
news:e6e0l7N%23HHA.464@xxxxxxxxxxxxxxxxxxxx
I just agree with Brian's answer. To test, please try to change the
stirng(basic_string)'s constructor to explicit, you will find that the
string s2 = (string)"test" could not compile at all.
Neither could string s2 = string("test"). And your point is... ?
Consider this program:
struct X {
explicit X(const X&) {}
X(char*) {}
};
int main()
{
X a = (X)"test";
X b = X("test");
return 0;
}
In my copies of VC7.1 and VC8, both lines produce
error C2558: struct 'X' : no copy constructor available or copy
constructor is declared 'explicit'
What do you believe can be done to the definition of X to make one line
compile and the other fail? Can you provide an example?
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- Re: string cast
- From: Alan Leng
- Re: string cast
- Prev by Date: Re: Help... global iterator causes assertion failure
- Next by Date: Re: disconnect std::ostream
- Previous by thread: Re: string cast
- Index(es):
Relevant Pages
|