Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
const test
#include <iostream> #include <string> #include <cstdlib> #include <cstdio> #include <cstring> using namespace std; class MyString { private: char *pBuf; public: MyString(const char *s=NULL) { if(s == NULL) { pBuf = new char[1]; pBuf[0] = NULL; } else { pBuf = new char[strlen(s) + 1]; strcpy(pBuf, s); } } MyString(const MyString& s){ cout << "not copy\n"; pBuf = new char[s.getSize() + 1]; strcpy(pBuf, s.pBuf); } ~MyString(){ if (pBuf) delete []pBuf; } void print() { cout << pBuf << endl; } int getSize() const { return strlen(pBuf); } }; int main() { char bf[] = "asdf"; MyString str1(bf); MyString str2("Hello"); MyString str3 = "World!"; str1.print(); str2.print(); str3.print(); }
run
|
edit
|
history
|
help
0
Defining Class Members
Get smallest dividers
ignat2
C++ lesson
Median of row wise sorted matrix
11080 WIP
queueLinkedlist
rstring
Riemann's prime number formula
HelloWorld