const变量和const类型变量的区别 [英] Difference between const variable and const type variable

查看:173
本文介绍了const变量和const类型变量的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两者之间的区别:



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类型变量的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆