Yeah, ok, I feel pretty stupid.

On 11/13/06, Byron Clark <[EMAIL PROTECTED]> wrote:

On Mon, Nov 13, 2006 at 10:05:45PM -0700, Daniel Dilts wrote:
> First bug:
> #include <string>
>
> int main()
> {
>    std::string a();
>    a="alskdfjasdj";
>    return 0;
> }
>
> output:
> test.cpp: In function int main():
> test.cpp:6: error: assignment of function std::string a()
> test.cpp:6: error: cannot convert const char [12] to std::string ()() in
> assignment
>
> #include <string>
>
> int main()
> {
>    std::string a("");
>    a="alskdfjasdj";
>    return 0;
> }
>
> This compiles.
>
> The bug is that std::string a() and std::string a("") should have
EXACTLY
> the same result.  The assignment of the C-string should work in both
cases.

The following are roughly equivalent:

std::string *a = new std::string();
std::string *a = new std::string("");

or even:

std::string a = std::string();
std::string a = std::string("");

but the following are different:

std::string a();    // function declaration
std::string a("");

See http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.2 for more
information.

You probably just want to use this line to declare an object on the
stack with the default constructor:

std::string a;

--
Byron Clark


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFFWVaEErN13QQr6mgRAnjrAJ90uCdTW9/JQmTR9YtFR+tlk2CjewCfWWfX
AaghZrB5yuQ9et6kkveu3TE=
=7dL1
-----END PGP SIGNATURE-----


--------------------
BYU Unix Users Group
http://uug.byu.edu/

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list


--------------------
BYU Unix Users Group http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG. ___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to