基本數組初始化我初學C++C++從初始化列表
我覺得這是微不足道的問題,但我沒有找到答案
爲什麼這個代碼給出了一個錯誤?而如果我們在一行中初始化數組 字節x [2] = {78,82}正常工作?
這兩種情況下x指針的區別是什麼?
// example: one class, two objects
#include <iostream>
using namespace std;
typedef unsigned char byte;
int main() {
byte x[2];
x = {78,82};
cout << x << endl;
}
我只能從NetBeans的
error: assigning to an array from an initializer list
C++原始數組無法(直接地)分配。改爲使用'std :: array'。它將原始數組包裹在一個'struct'中。 –
也許[這](http://stackoverflow.com/questions/15603158/error-assigning-to-an-array-from-an-initializer-list)將幫助你 – Noel
一*相似性*是'x'是不是任何情況下的指針,它是一個數組。 – molbdnilo