Re: string cast

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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


.



Relevant Pages

  • Re: data exchange between two windows
    ... But in C++ there's a constructor in the struct, ... I assume that this is what Joe is alluding to. ... buffer with an explicit length and therefore I want a struct, ...
    (microsoft.public.vc.mfc)
  • Re: Best way to implement default parameters
    ... The examples Dmitry posted for Ada would have the programmer explicitly ... E.g. is the caller required to mention the keywords, ... You recognize that "explicit values in the caller" has value, ... Which, then, could be either be bound to a specific look-and-feel at compile ...
    (comp.lang.misc)
  • Re: CString not working as advertised
    ... The following will not compile in a UNICODE application: ... CString kindOfFruit; ... Rather, the compiler should first construct a temporary CString using the const char* constructor, and then initialize kindOfFruit using the copy constructor. ... none of the CStringT constructors is explicit. ...
    (microsoft.public.vc.mfc)
  • Re: Panic switching to 64 bit kernel
    ... The only real reason to compile 64-bit is if you expect to be addressing ... explicit use of any additional 64 bit features. ... Both have the same number of general purpose registers. ...
    (comp.unix.solaris)
  • Re: remove structs default constructor?
    ... Ever heard of mistakes in MSDN? ... by the struct is set to 0. ... No there is no *explicit* .ctor created by the compiler for a value type as it's the case ... foolish to have a constructor when all you need to do is shove zero ...
    (microsoft.public.dotnet.languages.csharp)