Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. using namespace std;
  4.  
  5. class String
  6. {
  7. char *p;
  8. int len;
  9. public:
  10. String(const char *a);
  11. };
  12.  
  13. String::String(const char *a)
  14. {
  15. int length = strlen(a);
  16. p = new char[length +1];
  17. strcpy(p, a);
  18. cout << "Constructor Called " << endl;
  19. }
  20.  
  21. int main()
  22. {
  23. String s1("Geeks"); // line 1
  24. const char *name = "forGeeks";
  25. s1 = String(name); // line 3
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement