コンパイルがうまくいきません。
header file
#ifndef TIME_H #define TIME_H class Time { private : int hour; int minute; int second; public : //with default value Time(const int h = 0, const int m = 0, const int s = 0); // setter function void setTime(const int h, const int m, const int s); // Print a description of object in " hh:mm:ss" void print() const; //compare two time object bool equals(const Time&); }; #endif
#include <iostream> #include <iomanip> #include "Time.h" using namespace std; Time :: Time(const int h, const int m, const int s) : hour(h), minute (m), second(s) {} void Time :: setTime(const int h, const int m, const int s) { hour = h; minute = m; second = s; } void Time :: print() const { cout << setw(2) << setfill('0') << hour << ":" << setw(2) << setfill('0') << minute << ":" << setw(2) << setfill('0') << second << "\n"; } bool Time :: equals(const Time &otherTime) { if(hour == otherTime.hour && minute == otherTime.minute && second == otherTime.second) return true; else return false; }
main
#include <iostream> using namespace std; #include "Time.h" int main() { Time t1(10, 50, 59); t1.print(); // 10:50:59 Time t2; t2.print(); // 06:39:09 t2.setTime(6, 39, 9); t2.print(); // 06:39:09 if(t1.equals(t2)) cout << "Two objects are equal\n"; else cout << "Two objects are not equal\n"; return 0; }
コンパイルはしたのを一通り試しましたが、
c++ main.cpp -o main g++ main.cpp g++ -lstdc++ main.cpp -o main g++ -std=c++11 main.cpp -o main
帰ってくるのは以下です
Undefined symbols for architecture x86_64: "Time::equals(Time const&)", referenced from: _main in main-4fd42c.o "Time::setTime(int, int, int)", referenced from: _main in main-4fd42c.o "Time::Time(int, int, int)", referenced from: _main in main-4fd42c.o "Time::print() const", referenced from: _main in main-4fd42c.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
よろしくお願いします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/04 01:56