This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / C++ 问题请教box( std::string const& input_line );
能该为 box( std::string const * input_line ); 吗? 有什么不同吗? 我理解两者都将input_line 声明为 string 的指针呀.
正在学习, 请教.
-uvcare(uvcare);
2004-4-1
{172}
(#1668217@0)
-
reference was different with pointer. When you call this function, it would be different.
-bugkiller(Driver Coding);
2004-4-1
(#1668317@0)
-
There is a bit differenceBoth pass an address of a string variable. The call will be different
for example
string str_line;
If you use the definition box( std::string const& input_line ), the call is box(str_libne) while for box( std::string const* input_line ), the call will be box(&str_line). They will archieve the same functionality
-willington(居无定所);
2004-4-1
{320}
(#1668477@0)
-
说明为常数引用参数意味在函数体里面不能为它赋值,这是主要的。
-r-camera(30);
2004-4-1
(#1668492@0)
-
box( std::string const * input_line ); input_line 是否也是常数呢? 在函数体里面能为它赋值吗?
-uvcare(uvcare);
2004-4-1
(#1668701@0)
-
指针可以说明为常量型吗?我还真没用过
-r-camera(30);
2004-4-1
(#1668919@0)
-
好象是可以的, 见内
-uvcare(uvcare);
2004-4-2
{697}
(#1669282@0)
-
两者功能一样,只是表现形式不同。如果写成box( std::string * const input_line ); 就不同了。这表示指针本身不能改变。到底使用指针还是引用,要看你的爱好。用指针时你要多敲一个字母。仅此而已。
-fromchina1(WhoAmI);
2004-4-2
{153}
(#1669091@0)
-
Pointers and references are quite different, read more books please.
-canadiantire(Crappy Tire);
2004-4-2
(#1669120@0)
-
还可以写成 box( std::const string * const input_line ); 对吗? 学到现在, 还真没发现它们有本质区别.
-uvcare(uvcare);
2004-4-2
(#1669289@0)