头文件C ++出错

时间:2015-04-22 03:37:46

标签: c++

有人能告诉我这行代码有什么问题:

#ifndef TIME12_H
#define TIME12_H
#include <iostream>
using namespace std;
#include "time24.h"
class time12
{
    private:
    bool pm;
    int hours;
    int minutes;
    int seconds;
public:
    time12();
    time12(bool p, int h, int m, int s);
    time12(time24 a);
    friend ostream& operator<<(ostream &out, time12 &a);
    friend istream& operator>>(istream &in, time12 &a);
    int get_hours(){ return hours; };
    int get_minutes(){ return minutes; };
    int get_seconds(){ return seconds; };
};

#endif // TIME12_H

它在time12(time24 a);行上给出了以下错误:

error: expected ')' before 'a'

我正在使用Code :: Blocks IDE和MinGW。

time24.h文件是:

#ifndef TIME24_H
#define TIME24_H
#include "time12.h"
#include <iostream>
using namespace std;
class time24
{
private:
        int hours;
        int minutes;
        int seconds;
public:
    time24();
        time24(int h, int m, int s);
        friend ostream& operator<<(ostream &out, time24 &a);
        friend istream& operator>>(istream &in, time24 &a);
        int get_hours(){ return hours; };
        int get_minutes(){ return minutes; };
        int get_seconds(){ return seconds; };

};

#endif // TIME24_H

1 个答案:

答案 0 :(得分:0)

你的错误可能是因为你的get_hours()和其他人的函数实现在它们的末尾有一个额外的半冒号。你有 int get_hours(){...};
但你应该有 int get_hours(){...}