c++讨厌在文件中包含两种或两种以上的数据类型
C++ annoying included in file two or more data types
我正在尝试处理一个以前没有遇到过的问题。
我试过这个链接,但它对我没有好处。系统头文件/usr/include/i386_type .h出错我试图从类似的问题中寻找可能的解决方案,但这并没有帮助我解决自己的问题。
我重新排序并做了分号,但我仍然得到令人讨厌的错误
处理文件中包含的错误:
g++ -Wall -Wextra -c clock.cpp clock_main.cpp In file included from /usr/include/machine/_types.h:34,
from /usr/include/sys/_types.h:33,
from /usr/include/_types.h:27,
from /usr/include/unistd.h:71,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/os_defines.h:61,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++config.h:41,
from /usr/include/c++/4.2.1/iostream:44,
from clock.cpp:2:
/usr/include/i386/_types.h:37: error: two or more data types in declaration of ‘__int8_t’
In file included from /usr/include/machine/_types.h:34,
from /usr/include/sys/_types.h:33,
from /usr/include/_types.h:27,
from /usr/include/unistd.h:71,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/os_defines.h:61,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++config.h:41,
from /usr/include/c++/4.2.1/iostream:44,
from clock_main.cpp:2:
/usr/include/i386/_types.h:37: error: two or more data types in declaration of ‘__int8_t’
和一些导致错误的文件
clock_main.cpp
#include "clock.h"
#include <iostream> // line 2 cause of error by compiler
using namespace std;
int main(){
Clock clk_0 (86399); // 1 day - 1 sec
cout << "initial time" << endl;
clk_0.print_time();
++clk_0;
cout << "adding one second" << endl;
clk_0.print_time();
--clk_0;
cout << "subtracting one second" << endl;
clk_0.print_time();
return 0;
}
clock.h
#ifndef CLOCK_H
#define CLOCK_H
/*我们做了一个简单的时钟类我们还使用了重载操作符
的功能*/
class Clock{
public:
Clock (unsigned int i); // construct and conversion
void print_time() const; //formatted printout
void tick(); // add one second
void tock(); // subtract one second
Clock operator++() {tick(); return *this;}
Clock operator--() {tock(); return *this;}
~Clock() {};
private:
unsigned long tot_secs, secs, mins, hours, days;
}
#endif
clock.cpp
#include "clock.h"
#include <iostream> // the offending line
inline Clock::Clock(unsigned int i){
tot_secs = i;
secs = tot_secs % 60;
mins = (tot_secs / 60) % 60;
hours = (tot_secs / 3600) % 24;
days = tot_secs / 86400;
};
void Clock::tick(){
Clock temp = Clock (++tot_secs);
secs = temp.secs;
mins = temp.mins;
hours = temp.hours;
days = temp.days;
}
void Clock::tock(){
Clock temp = Clock (--tot_secs);
secs = temp.secs;
mins = temp.mins;
hours = temp.hours;
days = temp.days;
}
void Clock::print_time() const{
std::cout << days << " days: " << hours << " hours: " << mins <<
" minutes: " << secs << " seconds" << std::endl;
}
分号
class Clock{
public:
Clock (unsigned int i); // construct and conversion
void print_time() const; //formatted printout
void tick(); // add one second
void tock(); // subtract one second
Clock operator++() {tick(); return *this;}
Clock operator--() {tock(); return *this;}
~Clock() {};
private:
unsigned long tot_secs, secs, mins, hours, days;
} ;
// ^^
相关文章:
- 有没有办法提示用户使用哪种数据类型作为模板 c++
- 如何构造可以调用和返回两种不同类型的模板
- 当 c++ 需要一种数据类型并获取另一种数据类型时会发生什么?
- 有没有办法让C++函数采用具有相同成员的两种不同类型?
- 将一种数据类型的向量复制到同一数据类型的结构向量中的有效方法是什么
- 生成一个类Name_class并将两种数据类型存储在一个向量中
- 使用 Arduino 发送两种不同类型的传感器数据
- 如何获得将两种不同类型的相乘的结果类型?
- 尝试连接两种不同类型的结构来创建链表
- 如何获得C - 模板状行为,但仅允许实例化两种特定类型
- 为什么 c++ 编译器在对两种不同类型的数值变量使用"std::max()"函数时会出现错误
- 用于给定描述的哪种数据类型
- 比较C 中的两个数据类型
- 可以使用 std::p air 保存三种数据类型的向量
- 如何使用函数中的模板传递两种不同类型的参数
- 哪种数据类型用于存储文件名和文件大小的使用
- 两种模板类型的sizeof,当两者都是从一个基派生时
- 使用两种数据类型作为参数堆叠STL
- C++如何在一个向量中存储两种数据类型
- 函数定义中使用的两种数据类型to_string(long double _Val)