linux cc错误'没有命名类型'

时间:2017-10-04 15:57:50

标签: c++ linux gcc makefile

我正在尝试创建一个读取和写入缓冲区大小的程序,但没有标准库。到目前为止,我已经用头文件编写了一个main,但是每当我编译main时,我都会遇到错误,例如

In file included from main.cc:6:0:
DefaultClock.cpp: In member function ‘double AccurateClock::Time::getTotalMilliseconds() const’:
DefaultClock.cpp:10:14: error: ‘milliseconds’ does not name a type
         auto milliseconds =
              ^
DefaultClock.cpp:13:16: error: ‘milliseconds’ was not declared in this scope
         return milliseconds;
                ^
接下来的30多行

等等。有点卡在这里,可能是错误的原因是什么?我已经定义了类。

    #include "DefaultClock.h"

namespace AccurateClock {

    Time::Time(const timespec &timeValue) : timeValue(timeValue) {
    }

    double Time::getTotalMilliseconds() const {
        const double oneThousand = 1000;
        auto milliseconds =
                (timeValue.tv_sec * oneThousand) +
                (timeValue.tv_nsec / oneThousand);
        return milliseconds;
    }

    void Time::print(std::ostream &out) const {
        const double oneThousand = 1000;
        auto milliseconds = getTotalMilliseconds();
        auto secondsPart = (long)(milliseconds / oneThousand);
        auto millisecondsPart = (long)(milliseconds - (secondsPart * oneThousand));
        auto nsPart = (long)(
                (milliseconds * oneThousand) -
                (secondsPart * oneThousand * oneThousand) -
                (millisecondsPart * oneThousand));
        out << secondsPart << "sec, " << millisecondsPart << "ms, " << nsPart << "ns since the computer booted";
    }



    const Duration Time::operator-(const Time &a) const {
        auto difference = getTotalMilliseconds()
                          - a.getTotalMilliseconds();

        auto duration = Duration(difference);

        return duration;
    }

    const Time DefaultClock::getTime() {
        auto value = timespec();
        clock_gettime(_CLOCK_REALTIME, &value);
        auto time = Time(value);
        return time;
    }

    Duration::Duration(double value) : valueInMilliseconds(value) {
    }

    void Duration::print(std::ostream &out) const {
        out << valueInMilliseconds << "ms";
    }
}

0 个答案:

没有答案