开发者

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_; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜