C ++是一种无空间的语言吗? [英] Is c++ a space free language?

查看:128
本文介绍了C ++是一种无空间的语言吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #define PR(A,B)cout < (A)< (B)<< endl; 




- 错误 - > A未在范围内声明

- 错误 - > B未在范围内声明

- 错误 - >预期,beforecout


我认为C ++是空间自由的语言,但是当我写上面的代码,然后我看到一些错误。
我仍​​然在想我的控制台是否无法正常工作或者库?。



如果我没有错, C ++是一个无空格的语言?

解决方案

这是其中之一。使用 PR 后的空格,预处理器应该知道(A,B)是否是宏的一部分扩展或其参数?它不,并且简单地假设,无论它在哪里看到 PR ,它应该替换(A,B)cout < (A)< (B)<<



  std :: vector< std :: vector< int> > 

最后一个空格是必须的,否则编译器假设它是> ; 运算符。



另一个例子是:

  a + + b; 

两个 + 符号之间的空格是必须的,原因很明显。


 #define PR ( A, B )  cout << ( A ) << ( B ) << endl ;

- error -> A was not declared in scope
- error -> B was not declared in scope
- error -> expected "," before "cout"

I thought C++ was space free language but when I write above code, then I see some errors. I am still thinking "Is my console is not working properly or library?".

If I am not wrong, how can someone say "C++ is a space free language"?

解决方案

There are numerous exceptions where whitespace matters; this is one of them. With the space after PR, how is the preprocessor supposed to know whether (A,B) is part of the macro expansion, or its arguments? It doesn't, and simply assumes that wherever it sees PR, it should substitute ( A, B ) cout << ( A ) << ( B ) << endl ;.

Another place where whitespace matters is in nested template arguments, e.g.:

std::vector<std::vector<int> >

That final space is mandatory, otherwise the compiler assumes it's the >> operator. (Although I believe this is sorted out in C++0x).

Yet another example is:

a + +b;

The space in between the two + symbols is mandatory, for obvious reasons.

这篇关于C ++是一种无空间的语言吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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