0

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

我试过这个链接,但它对我没有好处。 系统头文件 /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’

以及一些导致错误的文件

时钟主程序.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;
}

时钟.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;
}
4

1 回答 1

4

分号

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;
}  ;
// ^^
于 2013-05-05T04:53:41.253 回答