我正在编写玩具日历。 它包含此模板会议类型:
#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;
我做错了什么?
答案 0 :(得分:1)
应该是
std::map<T, Meeting_t<T>*> MeetingMap;
顺便说一句,你的默认构造函数是错误的,因为你无法从中返回一个值。
您似乎已编写此代码以防止某人使用默认构造函数,但您自动生成默认构造函数的语句错误,因为您提供了自定义构造函数。