나는 장난감 달력을 코딩하고있다. 다음 템플릿 회의 유형이 포함됩니다.
#include <string>
#include <iostream>
#pragma once
using namespace std;
template <class T>
class Meeting_t
{
private:
T startTime;
T endTime;
string subject;
public:
Meeting_t(){
//do not delete, a default CTOR will be always created
//this way we at least know something is wrong
return NULL;
}
~Meeting_t(){
//members are all managed outside of the object
}
Meeting_t(T sTime, T eTime, string subj){
startTime = sTime;
endTime = eTime;
subject = subj;
}
//getters
inline T GetStartTime() { return startTime; };
inline T GetEndTime() { return endTime; };
inline string GetSubject() { return subject; };
// == implementation
inline bool operator == (Meeting_t otherMeeting) {
return GetStartTime() == otherMeeting.GetStartTime();
};
inline bool operator < (Meeting_t otherMeeting) {
return GetStartTime() < otherMeeting.GetStartTime();
};
inline bool operator > (Meeting_t otherMeeting) {
return GetStartTime() > otherMeeting.GetStartTime();
};
inline void Print(){
cout << "\n*** *** ***\n";
cout << "\nSubject is:\n";
cout << GetSubject();
cout << "\nStart time is:\n";
cout << GetStartTime();
cout << "\nEnd time is:\n";
cout << GetEndTime();
cout << "\n";
};
};
내 달력 골격은 다음과 같습니다.
#pragma once
#include <map>
#include "Meeting_t.h"
template <typename T>
class DayCalendar_t
{
public:
//CTORs
DayCalendar_t(){};
//DTOR
//Free all allocated memory allocated for the object
~DayCalendar_t(){};
private:
//fields
std::map<T, Meeting_t::template Meeting_t* <T>> MeetingMap;
};
보시다시피 C ++ 맵 템플릿을 사용하기로 선택했지만 마지막 줄의 구문에 대해 불평합니다.
std::map<T, Meeting_t::template Meeting_t* <T>> MeetingMap;
내가 무엇을 잘못하고 있지?
그것은해야한다
std::map<T, Meeting_t<T>*> MeetingMap;
그런데 기본 생성자는 값을 반환 할 수 없기 때문에 잘못되었습니다.
누군가가 기본 생성자를 사용하는 것을 막기 위해 이것을 작성한 것처럼 보이지만 사용자 지정 생성자를 제공했기 때문에 기본 생성자가 자동으로 생성된다는 진술은 잘못되었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다