问题描述
以下两者之间的区别:
const variable = 10;
和
const int variable = 10;
当没有定义类型时,标准中的变量是否被解释为一个整数类型?
const variable = 10
是无效的C ++,而 const int variable = 10;
是。 b
$ b
只有当你有一个类型 const variable = 10
c $ c> variable ,并且你有一个函数,该类型的未命名参数,采用默认参数:
typedef int variable;
void foo(const variable = 10);
What is the difference between:
const variable = 10;
and
const int variable = 10;
Does variable, per the standard, get interpreted as an integral type when no type is defined?
const variable = 10
is not valid C++, while const int variable = 10;
is.
The only time (that I can think of) that const variable = 10
would be valid is if you had a type named variable
and you had a function with an unnamed parameter of that type, taking a default argument:
typedef int variable;
void foo(const variable = 10);
这篇关于const变量和const类型变量的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!