부모를 기대하는 멤버 함수에 Child를 전달할 수 있지만 벡터를 사용할 때 일치하는 선언이 없다는 컴파일 오류가 발생합니다. 바닥Child 클래스의 벡터를 Parent 클래스의 벡터를 기대하는 함수로 전달하는 방법은 무엇입니까?
ServerEvent.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
Event.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
CorrelationEngineManager.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();
};
CorrelationEngineManager.cpp에서 getUniqueLabels()에 CorrelationEngineManager.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
가능한 중복 (HTTP : //stackoverflow.com/questions/2376334/c-how-do-i-pass-a-container-of-derived-classes-to-a-function-expecting-a-cont) – jogojapan