C++下面的类方法的参数和返回值,什么时候用* 什么时候用&
下面的方法的参数和返回值,什么时候用* 什么时候用&,有谁能讲讲,举一反三更好
1、
String(const char *str = NULL); //通用构造函数
String(const String &str); //拷贝构造函数
2、下面有的返回 String 有的返回& ?
String operator+(const String &str) const; //重载+
String& operator=(const String &str); //重载=
String& operator+=(const String &str); //重载+=
class String
{
public:
String(const char *str = NULL); //通用构造函数
String(const String &str); //拷贝构造函数
~String(); //析构函数
String operator+(const String &str) const; //重载+
String& operator=(const String &str); //重载=
String& operator+=(const String &str); //重载+=
bool operator==(const String &str) const; //重载==
char& operator[](int n) const; //重载[]
size_t size() const; //获取长度
const char* c_str() const; //获取C字符串
friend istream& operator>>(istream &is, String &str);//输入
friend ostream& operator<<(ostream &os, String &str);//输出
private:
char *data; //字符串
size_t length; //长度
};