相关疑难解决方法(0)

为什么带有const参数的函数声明允许调用带有非const参数的函数?

记下以下C++代码:

#include <iostream>
using std::cout;

int foo (const int);

int main ()
{
   cout << foo(3);
}

int foo (int a)
{
   a++;
   return a;
}
Run Code Online (Sandbox Code Playgroud)

请注意,原型foo()采用a const int并且定义采用int.这个编译没有任何错误......

为什么没有编译错误?

c++ compilation

12
推荐指数
2
解决办法
1702
查看次数

标签 统计

c++ ×1

compilation ×1