#include <iostream>using namespace std;class TestClass { char* m_data; int m_size;public: TestClass(void) { m_size = 0; } ~TestClass(void) { if (m_data) delete[] m_data; }void copyData(const char* data, int _size) { m_data = new char[_size]; memcpy(m_data, data, _size); m_size = _size; }int getDataSize(void) const { return m_size; }};void showSize(TestClass a){ cout << "size = " << a.getDataSize() << endl;}int main(){ const char* const szData = "ABC";TestClass a; a.copyData(szData,strlen(szData)+1);showSize(a);return 0;}
- 2 回答
- 0 关注
- 660 浏览
添加回答
举报
0/150
提交
取消