C++烦人的文件中包含两种或多种数据类型

标签 c++ compiler-errors header-files

我正在尝试处理我以前没有遇到过的问题。

我试过这个链接,但对我没有用。 Error in system header file /usr/include/i386_types.h 我试图从类似的问题中寻找可能的解决方案,但这并没有帮助我解决我自己的问题。

我重新排序并做了分号,但我仍然遇到烦人的错误

处理in文件包含错误:

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’

和一些导致错误的文件

时钟主程序

#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;
}

时钟.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

时钟.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++烦人的文件中包含两种或多种数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16381498/

相关文章:

c++ - 使用 CMAKE 生成 makefile 后 undefined reference

c++ - 如何直接使用ffmpeg将H264原始流写入mp4

c - TCP 数据包发送方错误

c++ - 头文件中的空类声明?

linux - 是否有一个 header 提供类似于 uint64_t 的类型,用于 Linux 或 gcc 中的 float 和 double ?

c++ - 当文件有足够的数据c++时无法从文件中读取足够的数据

c++ - 设计一个可以与其他库相互转换的类

c++ - 编译器找不到头文件中声明的函数

matlab - 将文本插入文件的功能。 Matlab的

c++ - 您可以在 C++ header 中包含 .cu 扩展 header 吗?