为什么我从编译器中得到"期望的不合格ID?}"?

Rom*_*man 0 c++ syntax boost compilation

我从这里复制粘贴此代码:

#include <boost/math/distributions/poisson.hpp>

namespace boost { namespace math {

template <class RealType = double, 
          class Policy   = policies::policy<> >
class poisson_distribution;

typedef poisson_distribution<> poisson;

template <class RealType, class Policy>
class poisson_distribution
{ 
public:
  typedef RealType value_type;
  typedef Policy   policy_type;

  poisson_distribution(RealType mean = 1); // Constructor.
  RealType mean()const; // Accessor.
}

}} // namespaces boost::math
Run Code Online (Sandbox Code Playgroud)

并获得编译器错误:

expected unqualified-id before »}«
Run Code Online (Sandbox Code Playgroud)

Sal*_*gar 5

您需要在类定义的外部闭括号上使用分号.可能是其他的东西,也许你可以粘贴完整的错误和行号

...
 RealType mean()const; // Accessor.
}; <---
...
Run Code Online (Sandbox Code Playgroud)

  • @Roman我不认为它应该是可编译的代码,而是显示`poisson_distribution`类模板的接口(包括模板参数). (2认同)