- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我写了一个类作为作业,以民用格式花费时间并将其转换为军用格式...其他一切正常,除了我的转换方法无法识别其自身类的数据字段并显示错误
这是我的类(class)。
#include <iostream>
#include <string>
using namespace std;
class Time
{
friend ostream & operator << (ostream &, const Time &);
friend istream & operator >> (istream &, Time &);
private:
int chour;
int cmin;
int csec;
string AMPM;
int mhour;
int mmin;
int msec;
public:
Time ();
Time (int, int, int, string);
void set_hour(int);
void set_min(int);
void set_sec(int);
void set_AMPM(string);
int get_hour();
int get_min();
int get_sec();
string get_AMPM();
void convert2military();
void operator ++ (int);
bool operator == (const Time&);
};
Time ::Time()
{
chour=0;
cmin=0;
csec=0;
AMPM=" ";
mhour=0;
mmin=0;
msec=0;
}
Time :: Time( int _hour, int _min, int _sec, string _AMPM)
{
chour=_hour;
cmin=_min;
csec=_sec;
AMPM=_AMPM;
}
void Time :: set_hour (int _hour)
{
if (_hour>=0 && _hour<12)
{chour=_hour;}
}
void Time :: set_min (int _min)
{
if (_min>=0 && _min<60)
{
cmin=_min;
}
}
void Time :: set_sec (int _sec)
{
if (_sec>=0 && _sec<60)
{
csec=_sec;
}
}
void Time :: set_AMPM (string _AMPM)
{
AMPM=_AMPM;
}
int Time :: get_hour ()
{
return chour;
}
int Time :: get_min ()
{
return cmin;
}
int Time :: get_sec ()
{
return csec;
}
string Time :: get_AMPM ()
{
return AMPM;
}
void Time :: operator ++ (int)
{
if ( csec>=0 && csec<60)
{
csec++;
}
else
{
csec=0;
if (cmin>=0 && cmin<60)
{
cmin++;
}
else
{
cmin=0;
if (chour>=0 && chour<12)
{
chour++;
}
else
{
chour=0;
}
}
}
}
bool Time :: operator == (const Time & obj)
{
if (chour==obj.chour && cmin==obj.cmin && csec==obj.csec)
{
return true;
}
else
{
return false;
}
}
ostream & operator << (ostream & out, const Time & obj)
{
int choice;
out<<endl<<endl;
cout<<"Press 1 to view civilian time\nPress 2 to view military time :";
cin>>choice;
switch (choice)
{
case 1:
{
cout<<endl<<endl;
out<<"Hour : "<<obj.chour<<endl;
out<<"Minutes : "<<obj.cmin<<endl;
out<<"Seconds : "<<obj.csec<<endl;
out<<"Complete time : "<<obj.chour<<" : "<<obj.cmin<<" : "<<obj.csec<<" "<<obj.AMPM<<endl;
return out;
break;
}
case 2:
{
cout<<endl<<endl;
out<<"Hour : "<<obj.mhour<<endl;
out<<"Minutes : "<<obj.mmin<<endl;
out<<"Seconds : "<<obj.msec<<endl;
out<<"Complete time : "<<obj.mhour<<" : "<<obj.mmin<<" : "<<obj.msec<<endl;
return out;
break;
}
default:
{
cout<<"Invalid entry\n";
break;
}
}
}
istream & operator >> (istream & in, Time & obj1)
{
cout<<"Enter hours : ";
in>>obj1.chour;
cout<<"Enter minutes : ";
in>>obj1.cmin;
cout<<"Enter seconds : ";
in>>obj1.csec;
cout<<"AM or PM ? : ";
cin>>obj1.AMPM;
return in;
}
void Time :: convert2military ()
{
if (AMPM=="AM")
{
mhours=chours;
mmins=cmins;
msec=csec;
}
if (AMPM=="AM" && hours==12)
{
mhours=0;
}
if (AMPM=="PM")
{
mhours=12+chours;
mmins=cmins;
msec=csec;
}
if (AMPM=="PM" && hours==12)
{
mhours=chours;
}
}
void main ()
{
Time obj1(4,11,35,"PM");
obj1.convert2military();
cout<<obj1;
}
错误是这个函数
void Time :: convert2military ()
{
if (AMPM=="AM")
{
mhours=chours;
mmins=cmins;
msec=csec;
}
if (AMPM=="AM" && hours==12)
{
mhours=0;
}
if (AMPM=="PM")
{
mhours=12+chours;
mmins=cmins;
msec=csec;
}
if (AMPM=="PM" && hours==12)
{
mhours=chours;
}
}
这是我遇到的错误列表
1>------ Build started: Project: Time class, Configuration: Debug Win32 ------
1> time class.cpp
~ (178): error C2065: 'mhours' : undeclared identifier
~ (178): error C2065: 'chours' : undeclared identifier
~ (179): error C2065: 'mmins' : undeclared identifier
~ (179): error C2065: 'cmins' : undeclared identifier
~ (182): error C2065: 'hours' : undeclared identifier
~ (184): error C2065: 'mhours' : undeclared identifier
~ (188): error C2065: 'mhours' : undeclared identifier
~ (188): error C2065: 'chours' : undeclared identifier
~ (189): error C2065: 'mmins' : undeclared identifier
~ (189): error C2065: 'cmins' : undeclared identifier
~ (192): error C2065: 'hours' : undeclared identifier
~ (194): error C2065: 'mhours' : undeclared identifier
~ (194): error C2065: 'chours' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
最佳答案
复数错误(又名打字错误):您将字段称为 chour
或 mhour
,但您想使用 chours
或 mhours
。
提示:如果编译器告诉您未声明标识符,那几乎总是拼写错误或缺少字段。
关于C++ : Class to convert time from 12 to 24 hours not recognizing its own data fields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19725970/
我在 Python(3.5 版)中尝试使用语音识别模块,但遇到了以下错误: 'AttributeError: 'Recognizer' object has no attribute 'recogni
我正在尝试编译 C++ 程序,但遇到一些问题。特别是,当我使用 x86_64-w64-mingw32-gcc 作为编译器时,它在编译过程中提示“tmp/src/libfastms/solver/sol
我正在尝试安装 R 的 plyr 包。这是错误消息: * installing *source* package ‘plyr’ ... ** package ‘plyr’ successfully u
我第一次尝试使用多个文件构建程序。只用 main.cpp 编译程序我从来没有遇到过任何问题。使用以下命令,结果如下: $ g++ -c src/CNumber.cpp src/CNumber.h -o
我正在努力通过 The Little Book About OS Development ,特别是关于帧缓冲区的部分(链接)。我能够成功地汇编、链接、转换成 ISO 文件并启动纯程序集,但是一旦我尝试
我有一个关于 Swift 中 UIPanGestureRecognizer 的奇怪案例。我有一个处理平移手势的函数,并在 UIGestureRecognizerDelegate 中指定“false”,
抱歉,标题太长了。 我正在尝试将我们的功能测试代码与我们的集成测试代码隔离开来,并使用 gradle 任务让它工作。它也有 95% 在 intellij 中工作,除了每次我做一个“gradle ide
我想编写一个软件,当 USB 拇指驱动器连接到 USB 端口时,它会自动将一些文件复制到 USB 拇指驱动器上。为此我想知道: 我如何编写一个 c++ 应用程序,在 USB 拇指驱动器连接时收到通知?
我现在正在使用 BACKTRACK 5,它几乎像 ubuntu,一个 debian 和它的 32 位,我安装了 nasm,我去看了 dr. paulcarter 的汇编语言教程并下载了他的示例程序 (
我正在尝试编译一个包含以下行的 makefile: gcc -I. -I/home/usr/Documents/MTV/include -ggdb3 -Wall -O2 -o ascii2bin.c
我去了Chocolatey website并复制安装文本并粘贴到管理员 cmd.exe(使用 Windows 7)。当我运行命令时,我得到: 'powershell' is not recognize
我目前正在使用 Eventstore,但收到以下错误:Could not recognize BadRequest; 来自: game process tick failed UnknownError
我正在使用 jquery-1.11.1,并尝试使用 :data 选择器,如上所述 https://api.jqueryui.com/data-selector/ 尝试查找具有特定键的所有元素,如下所示
我有一个滚动功能,我需要执行它来滚动到其容器中的最后一条消息,该容器是带有 chunk_id 的容器。问题是它按原样进入容器,但如果我将最后一个子添加到混合中,该功能将不起作用。有什么想法我做错了吗?
我正在使用 sphinx4 暂停线程,直到说出特定的关键字。第一次效果很好,但第二次我需要暂停线程, recognizer.recognize() 似乎没有运行,应用程序只是开始发送垃圾邮件“开始说话
我正在尝试检查我的应用程序是否被授予访问用户提醒的权限,方法是: EKEventStore *store = [[EKEventStore alloc] init]; EKAuthorizationS
我有一个 foo 对象,如下所示: var foo = { "timer" : { "hours" : 0, "minutes" : 0,
我正在尝试运行位于此处的代码: http://r3dux.org/2010/11/single-call-opengl-texture-loader-in-devil/ 而且它需要我使用 DevIL,
我交叉编译了arm的内核源代码,带有调试信息和KGDB。 当我在主机中运行 gdb 时: $ arm-linux-gnueabihf-gdb vmlinux ... Reading symbols f
我使用 pip 将 virtualenv 安装到我的项目目录中。但是,当我在 Windows 终端中运行命令 virtualenv venv 时,它只是告诉我它无法识别。 我必须在 Python 中做
我是一名优秀的程序员,十分优秀!