我有一個類有兩個向量:int和Str。現在我想定義一個拷貝構造函數,以便元素順序顛倒過來;例如如果a=(1,Hello),(2,World)和我寫auto b=a;我得到b=(2,world),(1,hello)。這是完美的工作。我遇到的問題是超載運算符=,以便使用複製構造函數。這裏是我的班加拷貝構造函數: class grade
{
private:
static int
我有一個類 class MyClass
{
public :
int a;
int b;
}
對於使用副本交換成語然後我創建函數 void MyClass::swap(MyClass& other)
{
std::swap(a,other.a);
std::swap(b,other.b);
}
如果,以後,我改變我的等級和刪除成員a,那麼編譯器會在swap
試圖給出這個問題的答案text-file-handling-in-c給引用cplusplus.com。我遇到了std::swap功能的流類型,如fstream。 所以我的問題是: 到底是什麼的交換功能的目的,例如對於'fstream'分別在哪種情況下我必須使用它? 引用到Q & A C++ std::ifstream in constructor problem我知道流類型是不可複製的。參照Q &