boost::resulf_of or BOOST_TYPEOF in return value type
all! I'm stuck with boost::result_of and BOOST_TYPEOF. I wanna use them for deducing return value type of method.
How c开发者_如何学Goan I implement something like this (this doesn't compile):
class A {
private:
int x_;
public:
BOOST_TYPEOF(x_) x() { return x_; }
};
Later I'll make macro that creates getters automatically.
The fact that you're getting an error from your compiler (when it works under 4.6.1) suggests a potential compiler bug that's fixed in later versions. That said, it's unusual to use BOOST_TYPEOF
on your own data members - after all, you should know what type they are, right? If you're looking to consolidate some complex logic to determine the right type, just use a typedef
:
private:
typedef int data_type;
data_type x_;
public:
data_type x() { return x_; }
精彩评论