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; //长度
};
相关推荐
C/C++中*和&的用法详解
在本篇文章中我们给大家总结了C/C++中*和&的用法以及相关的代码分享,有兴趣的朋友赶紧学习下吧。
详解C/C++ 的*和&用法
C/C++中 * 的用法 1>最简单的乘法: a*b; 2>可以注释: /**/ 3>指针:(最重要) 指针是指向变量的地址 简单的例子分析: int main() { int a = 3; int *b = &a; cout << a: << a << endl; cout << b: << b << endl; *b = 10; cout << &a: << &a << endl; cout << b: << b << endl; system(pause); } 结果: a:3 b:00EFFE28 &a:00EFFE28 b:00EFFE28 a
yaml-cpp库的编译&安装
yaml-cpp库的编译&安装 一、 下载 二、 解压缩 三、 编译&安装 四、 使用说明
C#调用C++ DLL类方法
C++的优势在于高效灵活,C#的优势在于简单易用,两者结合起来对项目开发来说是件好事,而且C++不容易反编译,也保障了代码的安全性,如果一些核心算法使用C#编写,那么保密就是一个问题。 C++生成的DLL一般只提供函数接口,不能直接用C#调用C++写的类,这样非常不方便,于是经过半天的反复测试,终于确定了一套可行的方案,下面就是整个流程的一个范例
C++ .h和.cpp文件总结
总结了.h文件能做什么,.cpp文件能做什么,总结了.h文件的本质,方便新手在遇到文件包含、类型声明、变量定义时能理清.h与.cpp关系,纯属个人总结文档。



