2013-03-26 311 views
1

大家好,我在这里是新的,我在嵌套类中声明构造函数时出错。C++错误C4091当继承嵌套类

可以说我有一个名为Event的类,在SampleEvent和TimeEvent构造函数中有2个继承它的SampleEvent和TimeEvent的嵌套类,但有一个错误。

这里是我的代码:

// Event Class 
#ifndef EVENT_H 
#define EVENT_H 

#include <iostream> 

namespace Engine 
{ 
    namespace Data 
    { 
     class Event 
     { 
      public: 
       // Class Variable 
       int Measure; 
       int Beat; 
       int Position; 

       // This Class that was I mean 
       class SampleEvent; 
       class TimeEvent; 

       // Constructor 
       Event(int measure, int beat, int pos); 
     }; 

     // Sample Event Class 
     class Event::SampleEvent : public Event 
     { 
      public: 
      // variable in SampleEvent Class 
      int ID; 
      float Pan; 
      float Vol; 

      // Constructor 
      SampleEvent(int id, float pan, float vol, int measure, int beat, int pos); 
     }; 

     // Time Event Class 
     class Event::TimeEvent : public Event 
     { 
      public: 
      // variable in TimeEvent Class 
      double Value; 

      // Constructor 
      TimeEvent(double value, int measure, int beat, int pos); 
     }; 

     // Constructor of Event 
     Event::Event(int measure, int beat, int pos) 
     { 
      Measure   = measure; 
      Beat   = beat; 
      Position  = pos; 
     } 

     // Constructor of Sample Event 
     Event::SampleEvent::SampleEvent(int id, float pan, float vol, int measure, int beat, int pos) : Event::Event(measure, beat, pos) 
     { 
      ID      = id; 
      Pan      = pan; 
      Vol      = vol; 
      Measure   = measure; 
      Beat   = beat; 
      Position  = pos; 
     } 

     // Constructor of Time Event 
     Event::TimeEvent::TimeEvent(double value, int measure, int beat, int pos) : Event::Event(measure, beat, pos) 
     { 
      Value     = value; 
      Measure   = measure; 
      Beat   = beat; 
      Position  = pos; 
     } 
    }  
} 
#endif 

这给我2错误:

Error C2039: '{ctor}' : is not a member of 'Engine::Data::Event' (line 60) 
Error C2039: '{ctor}' : is not a member of 'Engine::Data::Event' (line 71) 

有人可以帮助我吗? 谢谢

回答

0

int Position缺少分号。

而且,你在代码的末尾缺少一个右括号:

 }  
    } // <--- MISSING 
} 

但是,随着代码的主要问题是,你需要明确初始化基类的构造函数,因为默认的构造函数由于您定义了构造函数Event(int measure, int beat, int pos);,因此不会被隐式定义(也不能使用)。

Event::SampleEvent::SampleEvent(int id, float pan, float vol, 
           int measure, int beat, int pos) 
: Event(id, id, id) // This is just an example, pass the proper values here 
{ 
    //... 
} 

Event::TimeEvent::TimeEvent(double value, int measure, int beat, int pos) 
: Event(measure, measure, measure) // Pass the proper values to base ctor 

编辑

现在的错误是因为你使用Event::Event(measure, beat, pos)代替Event。 (不过,我认为Event::Event应该的工作,我认为这是不接受的代码在MSVC的错误。)

+0

感谢您的回复,看后,我已经修改了代码,但仍然得到同样的错误 – SirusDoma 2013-03-26 03:14:44

+0

@ChronoCross:将'Event :: Event'改为'Event'。 – 2013-03-26 03:17:42

+0

哇谢谢,解决我的问题(y)谢谢 – SirusDoma 2013-03-26 03:20:39