c++ - Why doesn't this compile? -
When I try to continue using the form first, G ++ gives me an "error: 'operator Does not match '' ASIS >> S '"But does two separate announcements do the same thing?
#include & lt; Iostream & gt; # Include & lt; Sstream & gt; #include & lt; String & gt; Int main () {const char * buf = "Hello World"; Std :: string SS (buf); // std :: istringstream iss (std :: string (buf)); // This std :: istringstream iss (ss) does not work; // but it does std :: string; Continue & gt; & Gt; S; }
This is called "the most unwanted parse" of C ++: Looks like an example announcement for you actually looks like the compiler's declaration function.
std :: string name (); // function declaration std :: string name; // Object declaration with default constructor std :: stringstream ss (std :: string (buf)); // function declaration std :: stringstream ss (std :: string buf); // Another task declaration std :: stringstream ss (std :: string); // also a function declaration std :: stringstream ss (std :: string ()); // above, the logic name is optional std :: stringstream ss ((std :: string (buf)); // object declaration
Note the additional brackets in the previous example.These bracket function The declaration will not be legal in the declaration.
The first example with the default constructor is well known. In the second case, the incompatibility that is called is that the brackets around the parameter name in C ++ are legal but optional For example, you have a function like this You can not define:
void foo (int (bar)) {}
Actually you will run in every direction when a constructor has all logic Constructive invoices are temporary by taking 0 or 1 arguments, and have to put additional brackets around one of the additional shapes for quick solutions.
Comments
Post a Comment