2017-02-09 10 views
1

私はC++を書いてからしばらくしていますが、メモリをリフレッシュするためにさまざまな種類のクロックを複製する簡単なプログラムを作成しようとしています。さらに別の 'メンバー宣言が見つかりません'

私はClockスーパークラスを書いて始めて、私のコンストラクタ/デストラクタ以外の各メソッドに対してMember declaration not foundを得ました。私はどこか小さな誤りだと推測しますが、私は何も見つけられません。

Clock.h

/* 
* Clock.h 
*/ 

#ifndef CLOCK_H_ 
#define CLOCK_H_ 

class Clock { 
private: 
    int seconds; 
    int minutes; 
    int hours; 

public: 
    Clock(); 
    Clock(int, int, int); 
    virtual ~Clock(); 
    virtual void tick() = 0; 
    void setTime(int, int, int); 
    void print(); 
}; 

#endif /* CLOCK_H_ */ 

Clock.cpp

/* 
* Clock.cpp 
*/ 

#include "Clock.h" 
#include <iostream> 

Clock::Clock() { 
    seconds = 0; 
    minutes = 0; 
    hours = 0; 
} 

Clock::Clock(int secs, int mins, int hrs) : 
     seconds(secs), minutes(mins), hours(hrs) { 
} 

Clock::~Clock() { 
    // TODO Auto-generated destructor stub 
} 

Clock::setTime(int secs, int mins, int hrs) { 
    seconds = secs; 
    minutes = mins; 
    hours = hrs; 
} 

Clock::print() { 
    std::cout << hours << ":" << minutes << ":" << seconds << std::endl; 
} 

答えて

1

私は、エラーメッセージが少し長くなり疑い、それは全体としてそれを見て役立つだろう。
言われていること 、エラーがあなたの定義があるべきという事実に起因することができます

void Clock::setTime(int secs, int mins, int hrs) { /* ... */ } 

の代わりに:、戻り値の型は、あなたのケースで

ある
Clock::setTime(int secs, int mins, int hrs) { /* ... */ } 

を逃しています。
printについても同様です。

0

実装ファイル(Clock.cpp)に次のメソッドの戻り値の型がありません。

void Clock::setTime(int secs, int mins, int hrs) { 
    seconds = secs; 
    minutes = mins; 
    hours = hrs; 
} 

void Clock::print() { 
    std::cout << hours << ":" << minutes << ":" << seconds << std::endl; 
} 
でなければなりません
Clock::setTime(int secs, int mins, int hrs) { 
    seconds = secs; 
    minutes = mins; 
    hours = hrs; 
} 

Clock::print() { 
    std::cout << hours << ":" << minutes << ":" << seconds << std::endl; 
} 

関連する問題