【发布时间】:2017-09-12 11:34:14
【问题描述】:
#include <iostream>
int main()
{
const int l_loc[3] = {1,2,3};
int (*l_loc2)[3] = NULL;
l_loc2 = const_cast<int (*)[3]>(l_loc); // complaining here.
std::cout<<l_loc2[1]<<std::endl;
return 0;
}
./example.cpp:7: error: invalid const_cast from type ‘const int*’ to type ‘int (*)[3]’
我只能修改那条尖线。请提供任何线索。
【问题讨论】:
-
@tobi303 UB 调情特技飞行?
-
@tobi303 - 可能是一个考试/面试问题
-
@StoryTeller 有一天我应该参加一次面试,只是为了看看面试官在我告诉他我拒绝从事类似工作时的表情。很高兴不是专业人士:P
-
@tobi303 - 令人钦佩。但值得庆幸的是,提出此类问题的公司越来越少。