实际上,我已经成功地使用普通数据类型成功地创建了一个动态分配的数组,但那是前一阵子(比如,六章!)而且我不知道为什么我不能在这里动态设置数组 - 我知道它给了我一个 int 错误,但我不能使用类类型,因为类类型不处理这样的数字。在这一点上,我很困惑。这是我的代码,包括标题:
#include <iostream>
#include "milTime.h"
#include "Time.h"
using namespace std;
int main()
{
milTime *theta;
bool amOrPm;
int milHr, milSc,milM,times;
cout<<"How many times would you like to convert?";
cin>>times;
theta = new milTime;
*theta = times;
这是我的错误:
错误 1 错误 C2440: '=' : 无法从 'int' 转换为 'milTime *' c:\users\heather\documents\visual studio 2012\projects\military time\military time\source.cpp 17 1 Military Time
任何帮助将不胜感激,因为除此之外我已经完全完成了。我和我的聪明想法让它被动态分配!
这是请求的 milTime 类:
#ifndef MILTIME
#define MILTIME
#include <iostream>
#include "Time.h"
class milTime : public Time
{
protected:
int milHours;
int milMins;
int milSeconds;
public:
void setTime(int h)
{
milHours = h;
}
void setMin(int m)
{
milMins=m;
}
void setSec(int s)
{
milSeconds=s;
}
int getmilHours()
{return milHours;}
int getmilMins()
{return milMins;}
int getmilSeconds()
{return milSeconds;}
bool timeConverter(int mTime, int mMins, int mSecs)
{
bool aOrPm;
min = mMins;
if(mTime<12)
{
hour = mTime;
aOrPm = false;
//AM will be false.
}
else if (mTime>12 && mTime<=24)
{
hour = mTime%12+1;
aOrPm = true;
}
sec = mSecs;
return aOrPm;
}
};
#endif