Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.75 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. A gcc compilation error (concerning copy c'tors) which seems odd (at least to me)
  2. testref.cpp: In function ‘int main()’:
  3. testref.cpp:10: error: ‘A::A(const A&)’ is private
  4. testref.cpp:20: error: within this context
  5.        
  6. #include <cstdio>
  7.  
  8. class A {
  9. public:
  10.     A() { i=0; printf("A ctorn"); }
  11.     ~A() { printf("A dtorn"); }
  12.  
  13. private:
  14.     A(const A& other) { i=other.i; printf("A COPY CTORn"); }
  15.     A& operator=(const A& other) { i=other.i; printf("A COPY operatorn"); return *this; }
  16. private:
  17.     int i;
  18. };
  19.  
  20. void f(const A &aref) {
  21.     printf("dummyn");
  22. }
  23.  
  24. int main() {
  25.     f(A());
  26.     return 0;
  27. }
  28.        
  29. test.cpp:20:7: warning: C++98 requires an accessible copy constructor for class
  30.               'A' when binding a reference to a temporary; was private
clone this paste RAW Paste Data