C++ 非静态或常量数组语法
这个语法有什么问题?很抱歉问你这个新手问题 资料来源:C++ 非静态或常量数组语法,c++,C++,这个语法有什么问题?很抱歉问你这个新手问题 资料来源: Level::Level() { NintyDegreeDirections[4] = { 1.0f, 1.4f, 2.4f, 0.1f } ...rest of class 标题: //all necessary includes class Level { private: float NintyDegreeDirections[4]; ...rest of header
Level::Level()
{
NintyDegreeDirections[4] =
{
1.0f, 1.4f, 2.4f, 0.1f
}
...rest of class
标题:
//all necessary includes
class Level
{
private:
float NintyDegreeDirections[4];
...rest of header
如何将数组作为实例成员?我正在从C#转换,您是否尝试过:
NintyDegreeDirections[0] = 1.0f;
NintyDegreeDirections[1] = 1.4f;
/* ... */
在当前版本的C++(C++ 11)中,可以初始化成员数组,例如:
Level::Level()
: NintyDegreeDirections( { 1.0f, 1.4f, 2.4f, 0.1f } )
{
}
C++11不是普遍支持的,如果您的编译器中没有对它的支持,您将不得不依次分配给每个成员
例如:
没有办法在一个块中初始化所有的vAUES?@ SirYakalot(ToLL)至今还没有C99那么现代。@ NC3B:请证明断言“C++没有C++那样的现代”。(表面上,C++比C99看起来更近12年)。CharlesBailey我是(半)拖曳,思考复合文字。你能解释这个C++ C99的东西吗?
NintyDegreeDirections[0] = 1.0f;
NintyDegreeDirections[1] = 1.4f;
//...