Mat*_*oli 0 c c++ pointers coding-style
哪一个是最好的写作方式:
string* str
Run Code Online (Sandbox Code Playgroud)
要么:
string *str
Run Code Online (Sandbox Code Playgroud)
其中一个有副作用的缺点吗?
谢谢
更喜欢第二个的原因是你一次声明多个变量:
string *str, *foo;
string* str, foo;
Run Code Online (Sandbox Code Playgroud)
这两条线是不同的,第一个宣告指针,而第二个声明一个指针string和一个string.
[FredOverflow的评论]这个问题可以通过一些模板魔术来解决;但是;-)
template <typename T>
struct multiple
{
typedef T variables;
};
multiple<string*>::variables str, foo;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1621 次 |
| 最近记录: |