N
Neil Zanella
Hello,
It seems to me that default parameters can be anything including something
called with a constructor, but using the this pointer in as a default
parameter inside is not allowed it seems, as compiling the following
program illustrates. I wonder what the C++ standard has to say about
this. I am also interested in knowing why the designers of C++
decided to disallow this feature.
Best Regards,
Thanks,
Neil
class Foo {
public:
Foo(int x = 0): x(x) { }
private:
Foo *hello(Foo *foo = this); //invalid
int x;
};
Foo *Foo::hello(Foo *foo) {
return foo;
}
int main() {
Foo foo;
}
It seems to me that default parameters can be anything including something
called with a constructor, but using the this pointer in as a default
parameter inside is not allowed it seems, as compiling the following
program illustrates. I wonder what the C++ standard has to say about
this. I am also interested in knowing why the designers of C++
decided to disallow this feature.
Best Regards,
Thanks,
Neil
class Foo {
public:
Foo(int x = 0): x(x) { }
private:
Foo *hello(Foo *foo = this); //invalid
int x;
};
Foo *Foo::hello(Foo *foo) {
return foo;
}
int main() {
Foo foo;
}