Re: string
From: hangaround (anonymous_at_discussions.microsoft.com)
Date: 02/23/05
- Next message: Kevin Frey: "auto_ptr pass-by-value to a method results in erroneous object destruction"
- Previous message: Hendrik Schober: "Re: string"
- In reply to: Ulrich Eckhardt: "Re: string"
- Next in thread: Tom Widmer: "Re: string"
- Reply: Tom Widmer: "Re: string"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 22 Feb 2005 19:32:24 -0800
>-----Original Message-----
>hangaround wrote:
>> const char *a = "11";
>> std::bitset<8> header(std::string(a));
>
>Other than what you (and many others) might expect, this
does _not_ create a
>bitset but declares a function called 'header' that takes
a std::string and
>returns a std::bitset<8>. Yes, local functions are not
part of C or C++,
>but local function declarations are.
>
>This is a popular mistake, workarounds are e.g.
>
> std::bitset<8> header((std::string(a)));
> std::bitset<8> header(static_cast<std::string>(a));
> std::bitset<8> header = std::bitset<8>(std::string(a));
>
>> Why the code above couldnot be compiled?
>
>What error message do you get? Next time, try to give
more info!
>
>Uli
>
>.
>
std::bitset<8> header((std::string(a)));
This workaround doesn't work!
VC complains as following:
Compiling...
main.cpp
E:\VcProject\CodeForRead\Experience\Try\main.cpp(8) :
error C2061: syntax
error : identifier 'a'
E:\VcProject\CodeForRead\Experience\Try\main.cpp(8) :
error C2066: cast to
function type is illegal
E:\VcProject\CodeForRead\Experience\Try\main.cpp(8) :
error C2059: syntax
error : ')'
E:\VcProject\CodeForRead\Experience\Try\main.cpp(9) :
error C2065: 'header'
: undeclared identifier
E:\VcProject\CodeForRead\Experience\Try\main.cpp(9) :
error C2228: left of
'.size' must have class/struct/union type
E:\VcProject\CodeForRead\Experience\Try\main.cpp(11) :
error C2109:
subscript requires array or pointer type
Error executing cl.exe.
main.obj - 6 error(s), 0 warning(s)
- Next message: Kevin Frey: "auto_ptr pass-by-value to a method results in erroneous object destruction"
- Previous message: Hendrik Schober: "Re: string"
- In reply to: Ulrich Eckhardt: "Re: string"
- Next in thread: Tom Widmer: "Re: string"
- Reply: Tom Widmer: "Re: string"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|