正确的C指针符号 [英] Correct C pointer notation

查看:203
本文介绍了正确的C指针符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个写的最好的方式:

Which one is the best way to write:

string* str

或者

string *str

有没有副作用对他们中的任何一个缺点?

Is there any drawback of side effect to one of them ?

感谢

推荐答案

一个原因preFER第二个是当你在一次声明多个变量:

A reason to prefer the second one is when you declare multiple variables at once:

string *str, *foo;
string* str, foo;

这两个行是不同的,第一个声明为指针,而第二个声明了一个指向字符串和一个字符串

[按FredOverflow注释]这个问题可以通过一些模板魔术来解决,虽然; - )

[Comment by FredOverflow] This problem can be solved by some template magic, though ;-)

template <typename T>
struct multiple
{
    typedef T variables;
};

multiple<string*>::variables str, foo;

这篇关于正确的C指针符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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