这个
class X
{
int x = 2;
string y {"smt"};
int tab[3] = {1,2,3}; // or tab[3] {1,2,3}
};
Run Code Online (Sandbox Code Playgroud)
据我所知,在新的C++ 11标准中是可行的.但是,Visual Studio 2012 V3或2013中不允许这样做.第一个给出:
error C2864: 'A::a' : only static const integral data members can be initialized within a class
Run Code Online (Sandbox Code Playgroud)
关于';'的第二和第三个错误 和'{'.
它是否基本上意味着这些功能在MS编译器中仍然不可用?什么编译器实际支持它?我在Visual中搜索了关于类内初始化的答案,但没有找到关于最新版本的具体内容.
提前致谢.
当尝试使用新版本的boost 1.65.1编译我的项目时,我收到以下错误:
C:\Users\twozn\Dev\soundtoolkit\stk\libraries\boost/geometry/strategies/distance.hpp(101): error C2664: 'int boost::mpl::assertion_failed<false>(boost::mpl::assert<false>::type)': cannot convert argument 1 from 'boost::mpl::failed ************(__cdecl boost::geometry::strategy::distance::services::default_strategy<boost::geometry::point_tag,boost::geometry::segment_tag,boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,boost::geometry::cartesian_tag,boost::geometry::cartesian_tag,void>::NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE_COMBINATION::* ***********)(boost::mpl::assert_::types<Point1,Point2,CsTag1,CsTag2>)' to 'boost::mpl::assert<false>::type'
1> with
1> [
1> Point1=boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,
1> Point2=boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,
1> CsTag1=boost::geometry::cartesian_tag,
1> CsTag2=boost::geometry::cartesian_tag
1> ]
Run Code Online (Sandbox Code Playgroud)
这是由线触发的
std::vector<Value> results;
rtree.query(boost::geometry::index::nearest(Point(p.x, p.y), 1), std::back_inserter(results));
Run Code Online (Sandbox Code Playgroud)
其中rtree上述被定义为
using Point = boost::geometry::model::point<float, 2,boost::geometry::cs::cartesian>;
using Segment = boost::geometry::model::segment<Point>;
using Value = std::pair<Segment, size_t>;
boost::geometry::index::rtree<Value, boost::geometry::index::rstar<16>> rtree;
Run Code Online (Sandbox Code Playgroud)
触发的断言是(boost/geometry/strategies/distance.hpp):
template
<
typename GeometryTag1,
typename GeometryTag2,
typename Point1,
typename Point2 = Point1,
typename CsTag1 = typename cs_tag<Point1>::type,
typename CsTag2 = …Run Code Online (Sandbox Code Playgroud) 我有一类Enemy我希望成为所有敌人类型的基类,也是纯粹的抽象类.此时,派生类应共享其所有成员和方法.特别是,存在loadTexture使用静态成员的方法texture.
class Enemy
{
int hp;
int damage;
//
// all other fields
//
static TextureClass* texture; //needs to be static because every instance
//of enemy uses the same texture
public:
static void loadTexture()
{
CreateTextureFromFile("somefilepath",&texture); //needs to be static
// because textures are loaded before any instance is crated
}
void draw()
{
DrawToScreen(&texture, ...many data members passed here...);
}
};
TextureClass* Enemy::texture = nullptr;
Run Code Online (Sandbox Code Playgroud)
现在,如果我想制作Enemy抽象并创建不同的敌人类型,显而易见的选择将是继承.所以我创建:
class EnemyA : Enemy
{ …Run Code Online (Sandbox Code Playgroud)