M
mimi
Hi, guys.
I am reading the C++ faq this days. When I am reading the faq 10.19, i
am not quite sure about it. I tested the code in my VC 6.0, and it
works fine. Who is right? The faq author or the comiler? My personal
preference would be the author. But could someone explain the issue
more clearly for me? I do not quite understand the explanation in the
faq, especially this sentece "When the compiler sees Foo x(Bar()), it
thinks that the Bar() part is declaring a non-member function that
returns a Bar object, so it thinks you are declaring the existence of a
function called x that returns a Foo and that takes as a single
parameter of type "non-member function that takes nothing and returns a
Bar."
The faq is http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.19
My code for test:
#include <iostream>
using namespace std;
class Bar {
public:
Bar() {}
};
class Foo {
public:
Foo(const Bar& b) {} // or perhaps Foo(Bar b)
void blah() {std::cout << "hi\n";}
};
int main()
{
Foo x(Bar());
x.blah();
}
I am reading the C++ faq this days. When I am reading the faq 10.19, i
am not quite sure about it. I tested the code in my VC 6.0, and it
works fine. Who is right? The faq author or the comiler? My personal
preference would be the author. But could someone explain the issue
more clearly for me? I do not quite understand the explanation in the
faq, especially this sentece "When the compiler sees Foo x(Bar()), it
thinks that the Bar() part is declaring a non-member function that
returns a Bar object, so it thinks you are declaring the existence of a
function called x that returns a Foo and that takes as a single
parameter of type "non-member function that takes nothing and returns a
Bar."
The faq is http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.19
My code for test:
#include <iostream>
using namespace std;
class Bar {
public:
Bar() {}
};
class Foo {
public:
Foo(const Bar& b) {} // or perhaps Foo(Bar b)
void blah() {std::cout << "hi\n";}
};
int main()
{
Foo x(Bar());
x.blah();
}