Can I declare and allocate memory to an array in class as given below:
1 2 3 4 5 6 7 8 9
|
class hci_test
{
public:
unsigned char* host_hci_pkt_arr;
host_hci_pkt_arr = new(nothrow) unsigned char [2];
host_hci_pkt_arr[0] = 0x01;
host_hci_pkt_arr[1] = 0x02;
};
|
While I am compiling above following errors are generated:
std::nothrow’ cannot appear in a constant-expression
hci_test.cpp:75: error: ‘new’ cannot appear in a constant-expression
hci_test.cpp:75: error: ISO C++ forbids declaration of ‘host_hci_pkt_arr’ with no type
hci_test.cpp:75: error: ISO C++ forbids initialization of member ‘host_hci_pkt_arr’
hci_test.cpp:75: error: making ‘host_hci_pkt_arr’ static
hci_test.cpp:75: error: ISO C++ forbids in-class initialization of non-const static member ‘host_hci_pkt_arr’
hci_test.cpp:75: error: declaration of ‘int hci_test::host_hci_pkt_arr’
hci_test.cpp:69: error: conflicts with previous declaration ‘unsigned char* hci_test::host_hci_pkt_arr’
Please tell me the solution.