我可以将 Child 传递给期望 Parent 的成员函数,但是在使用向量时出现编译错误,提示没有匹配的声明。请参阅底部对 getUniqueLabels() 的 CorrelationEngineManager.cpp 调用
服务器事件.h
#ifndef SERVEREVENT_H
#define SERVEREVENT_H
#define SERVEREVENT_COLS 3
#include "Event.h"
#include <vector>
class ServerEvent: public Event {
private:
public:
ServerEvent(std::vector<std::string> tokens);
void print();
};
#endif
事件.h
#ifndef EVENT_H
#define EVENT_H
#include <string>
#define EVENT_STOP 0
#define EVENT_START 1
class Event {
private:
protected:
double time;
std::string label;
int type; // EVENT_START OR EVENT_STOP
public:
};
#endif
相关引擎管理器.h
class CorrelationEngineManager {
private:
std::vector<ServerEvent> s_events;
std::vector<UPSEvent> u_events;
std::vector<TimeRecord> s_timeRecords;
std::vector<TimeRecord> u_timeRecords;
// typeOfEvent gets type of event, 0 for error, look at #defines for codes
int typeOfEvent(std::vector<std::string>);
int createTimeRecords();
std::vector<std::string> getUniqueLabels(std::vector<Event> events);
public:
CorrelationEngineManager();
//~CorrelationEngineManager();
int addEvent(std::vector<std::string> tokens); //add event given tokens
void print_events();
};
相关引擎管理器.cpp
int CorrelationEngineManager::createTimeRecords() {
std::vector<std::string> u_sLabels; // unique server labels
std::vector<std::string> u_uLabels; // unique UPS labels
u_sLabels = getUniqueLabels(s_events);
// u_uLabels = getUniqueLabels(u_events);
return 1;
}
// returns a vector of unique labels, input a vector of events
std::vector<std::string> CorrelationEngineManager::getUniqueLabels(std::vector<Event> events) {
std::vector<std::string> temp;
return temp;
}
编译错误
CorrelationEngineManager.cpp: In member function ‘int CorrelationEngineManager::createTimeRecords()’:
CorrelationEngineManager.cpp:60: error: no matching function for call
to ‘CorrelationEngineManager::getUniqueLabels(std::vector<ServerEvent,
std::allocator<ServerEvent> >&)’ CorrelationEngineManager.h:23: note:
candidates are: std::vector<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >
CorrelationEngineManager::getUniqueLabels(std::vector<Event,
std::allocator<Event> >) make: *** [CorrelationEngineManager.o] Error 1