标签:临时对象 拷贝 函数指针 this 派生 一个 har 构造函数 else
#include <iostream> using namespace std; class Node { public: Node(const char*str="",int a = 0):m_a(a) { if (str == NULL) { m_p = new char[1]; m_p[0] = ‘\0‘; } else { m_p = new char[strlen(str)+1]; strcpy(m_p, str); m_p[strlen(str)] = ‘\0‘; } } Node(const Node& n) { int len = strlen(n.m_p); m_p = new char[len + 1]; strcpy(m_p,n.m_p); m_a = n.m_a; } Node& operator=(const Node& n) { if (this != &n) { Node temp(n); char* temp_str = temp.m_p; temp.m_p = m_p; m_p = temp_str; m_a = n.m_a; } return *this; } virtual ~Node() { delete m_p; } private: char* m_p; int m_a; }; int main() { Node a("abcd",10); Node b(a); Node c; c = a; }
标签:临时对象 拷贝 函数指针 this 派生 一个 har 构造函数 else
原文地址:https://www.cnblogs.com/single-dont/p/11379488.html