C++相談室 part46
■ このスレッドは過去ログ倉庫に格納されています
0227デフォルトの名無しさん
2006/01/21(土) 01:28:53typedef int arrint[10][10];
arrint * p = new(arrint);
この場合、gcc-3.4.4(cygwin)とVC++7.1の両方で上手くいきませんでした。勘違いしてますかね。
VC++
arrint.cpp(5) : error C2440: 'initializing' : cannot convert from 'int (*)[10]' to 'arrint (*)'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style
g++
arrint.cpp:5: error: cannot convert `int (*)[10]' to `int (*)[10][10]' in initialization
また配列に対する代入および参照のところでgccのだけは挙動がおかしいかったです。VC++では完璧。
(*(arrint*)p)[0][12] = 3; //OK
//((arrint&)p)[0][12] = 3; //gccでは0になる
//reinterpret_cast<arrint&>(p)[1][2] = 3; //gccでは0になる
std::cout << (*(arrint*)p)[1][2] << std::endl; //代入した値を取得できる
//std::cout << ((arrint&)p)[1][2] << std::endl; //なぜか5になる。
//std::cout << reinterpret_cast<arrint&>(p)[1][2] << std::endl; //なぜか5になる。
■ このスレッドは過去ログ倉庫に格納されています