c++ 使用 CLI 数组初始化值静态 int
c++ initialize values static int with CLI array
所以我有 2 个数组,都是二维 cli::arrays。初始化 cli::array 的正确语法是什么。我在下面的示例中尝试过,但这不起作用。
//Cords.h
ref class Cords {
private:
static array<int,2>^ Xcord = gcnew array<int,2>(4,4); // [4][4]
static array<int,2>^ Ycord = gcnew array<int,2>(4,4); // [4][4]
public:
Cords();
static int getX(void);
static int getY(void);
};
int Cords::Xcord[0][0] = 4234; //On these lines is the mistake
int Cords::Ycord[0][0] = 2342; //On these lines is the mistake
所以我用静态构造函数解决了这个问题,我注意到你应该输入 [0,0] 而不是 [0][0]。我习惯了普通的 C 数组。
//Cords.h
ref class Cords {
private:
static array<int,2>^ Xcord = gcnew array<int,2>(4,4); // [4][4]
static array<int,2>^ Ycord = gcnew array<int,2>(4,4); // [4][4]
static Cords() { //static constructor to initialize values
Xcord[0,0] = 4234; // [0,0] instead of [0][0]
Ycord[0,0] = 2342;
...
}
public:
Cords();
static int getX(void);
static int getY(void);
};
相关文章:
- 枚举成员与静态 int 成员?
- 如何使用静态多态性在 int 和指针类型之间进行转换?
- 将 static_cast<int>(-15) 分配给静态常量字符类型变量
- std::out_of_range 在静态 int 变量上
- 打印一个带有静态 int 的函数,有一个 std::cout 和多个 std::cout 有什么区别?
- 错误:无效使用非静态成员函数"int test::hotplug_callback(libusb_contex
- 覆盖性静态分析说无符号的int是char(C++)
- C 未解决的外部符号(公共静态INT)
- 如何添加到静态 int +1
- 为什么c++编译器接受这种初始化?静态int x=x
- 静态 int 和 int 在 C++ 类中的区别
- 静态 (<int>PASS_OBJECT) 模板化数组在创建所述类型的对象时丢失数据?
- 静态 int 初始化
- 在这种情况下,静态 int 的值会发生变化吗?
- C++ 将静态 int 的值赋值分配给 int
- 具有大的2d数组:静态int与int
- 如何在c++函数中声明和初始化静态int
- 静态int数组中的类问题
- 静态int执行多少次
- c++ 使用 CLI 数组初始化值静态 int