我有3个类,一个是基类,另一个是从基类继承的类,这里是类的代码:
// Event Class
#ifndef EVENT_H
#define EVENT_H
#include <iostream>
namespace Engine
{
namespace Data
{
// base class
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 (inherit to 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 (inherit to 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(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(measure, beat, pos)
{
Value = value;
Measure = measure;
Beat = beat;
Position = pos;
}
}
}
#endif
假设,我有 2 个变量,SE
对于SampleEvent 和 TE 的 TimeEvent TE
,SE
我只想将它们插入向量,并从向量中获取它们,这是我当前的代码:
Event::SampleEvent SE = Event::SampleEvent(1000, 0, 0, 10, 10, 10);
Event::TimeEvent TE = Event::TimeEvent(200, 20, 20, 20);
vector<Event> DataEvent;
// insert Event
DataEvent.push_back(SE);
DataEvent.push_back(TE);
// Now I just want to get it back
Event::SampleEvent RSE = DataEvent[0]; // -> Error no suitable user-defined conversion from "Engine::Data::Event" to "Engine::Data::Event::SampleEvent" exists
Event::TimeEvent RTE = DataEvent[0]; // -> Error no suitable user-defined conversion from "Engine::Data::Event" to "Engine::Data::Event::TimeEvent" exists
// And I don't know how to detecting the inheritance Class
// something like if (RSE == Event::SampleEvent) or if (RTE == Event::TimeEvent) @_@