JetForMe

must explicitly initialize the base class

Jan 18th, 2013
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #import <string>
  2.  
  3.  
  4. class A
  5. {
  6. };
  7.  
  8. class B
  9. {
  10. };
  11.  
  12. class C
  13. {
  14. public:
  15.     C(const std::string& inS);
  16.     C(const std::string& inS, A* inA);
  17.    
  18.     virtual ~C();
  19. };
  20.  
  21.  
  22.  
  23.  
  24. class D : public virtual C, public virtual B
  25. {
  26. public:
  27.     D(const std::string& inS, B* inB)
  28.         :
  29.         C(inS)
  30.     {
  31.     }
  32. };
  33.  
  34.  
  35.  
  36.  
  37. class E : public virtual D, public virtual A
  38. {
  39. public:
  40.     E(const std::string& inS, B* inB)
  41.         :
  42.         D(inS, inB)
  43.     {
  44.     }
  45. };
  46.  
  47.  
  48. -----------------
  49.  
  50. Why does the above code get this error:
  51.  
  52.  
  53. $ clang Test.cpp
  54. Test.cpp:40:5: error: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
  55.     E(const std::string& inS, B* inB)
  56.     ^
  57. Test.cpp:12:7: note: 'C' declared here
  58. class C
  59.       ^
  60. 1 error generated.
Advertisement
Add Comment
Please, Sign In to add comment