Fernando
2010-09-29 11:33:02 UTC
Hi people,
I want to write something like this example ( C++0x )
class comparable
{
public:
bool is_equal( decltype(*this) other ) // should be X&
{
return true; // no matter
}
};
I get the following errors
MSVC10 -> Error 1 error C2355: 'this' : can only be
referenced inside non-static member functions
MinGW (GCC 4.6) -> invalid use of 'this' at top level
In the n1478.pdf paper (
http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1478.pdf ) are examples
that use decltype with "this" keyword, but not as an argument.
class X {
void foo() {
decltype(this) // X*
decltype(*this) // X&
...
}
void bar() const {
decltype(this) // const X*
decltype(*this) // const X&
...
}
};
Sorry for the comparisons, but in the Eiffel language you can write
something like this ...
is_equal (other: like Current) : BOOLEAN
Current is the same that C++ this.
other argument will be the same type as the class where the method is
written.
I wonder whether this alternative decltype (*this) is left out for some
specific reason or if you know any other way to achieve the same result.
Thanks,
Fernando Pelliccioni.
I want to write something like this example ( C++0x )
class comparable
{
public:
bool is_equal( decltype(*this) other ) // should be X&
{
return true; // no matter
}
};
I get the following errors
MSVC10 -> Error 1 error C2355: 'this' : can only be
referenced inside non-static member functions
MinGW (GCC 4.6) -> invalid use of 'this' at top level
In the n1478.pdf paper (
http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1478.pdf ) are examples
that use decltype with "this" keyword, but not as an argument.
class X {
void foo() {
decltype(this) // X*
decltype(*this) // X&
...
}
void bar() const {
decltype(this) // const X*
decltype(*this) // const X&
...
}
};
Sorry for the comparisons, but in the Eiffel language you can write
something like this ...
is_equal (other: like Current) : BOOLEAN
Current is the same that C++ this.
other argument will be the same type as the class where the method is
written.
I wonder whether this alternative decltype (*this) is left out for some
specific reason or if you know any other way to achieve the same result.
Thanks,
Fernando Pelliccioni.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]