Write a simple C + + clock class, put into the header file, the main function in the call header file compilation error, the specific code is as follows:
clock.h:
#include <iostream>
using namespace std;
class Clock
{
private:
int h,m,s;
public:
Clock();
~Clock();
void SetTime(int h,int m,int s);
void AddOneS();
void ShowTime();
};
void Clock::SetTime(int h,int m,int s)
{
this->h = h;
this->m = m;
this->s = s;
}
void Clock::ShowTime()
{
cout<<h<<":"<<m<<":"<<s<<endl;
}
Main function:
#include "clock.h" //When calling custom headers, use "" instead of<>
using namespace std;
int main(void)
{
Clock c1,c2;
c1.SetTime(2,45,36);
c2.SetTime(6,40,34);
c1.ShowTime();
c2.ShowTime();
return 0;
}
Error prompt:
Check the error because “reference clock:: clock() and clock:: clock() are not defined”
It turns out that there is no function body for constructors and destructors
(1) : define function body in class: clock () {} ~ clock () {}
(2) : define function body outside class: void clock:: clock() {} void clock:: ~ clock() {}
Read More:
- QT: error: undefined reference to ‘XXXX’ error prompt, solution
- The solution of undefined reference to error
- libxx.so: undefined reference, vector.reserve(n) [How to Solve]
- Solutions for undefined reference to ‘xxx’ encountered during linking
- Undefined reference to ‘CV:: imread (CV:: String const & int)’
- undefined reference to `pthread_create’ collect2: ld returned 1 exit status
- In function `_start’ undefined reference to `main’ error: ld returned 1 exit status
- undefined reference to `WinMain‘collect2.exe: error: ld returned 1 exit status
- [Solved] undefined reference to ‘cv::xfeatures2d::SIFT::create(…)’
- main.cpp : (. Text + 0xd06): undefined reference to XX method | simple record
- About “undefined reference to” when compiling uboot__ aeabi_ unwind_ cpp_ The solution of “PR0 ‘”
- Solving CodeBlocks OpenGL glew undefined reference to`_ imp__ Glewinit ‘error
- Vitis: platform out of date, makefile error at compile time; The modified application compiles to undefined reference
- Python 3.4 compiler prompt error: unexpected indent
- Error: undefined reference to ‘CV:: xxx’ encountered in using OpenCV in QT
- ninja Compiling the C compiler identification source file CMakeCCompilerId.c failed
- JS prompt cannot read property ‘style’ of undefined
- [Solved] Linux C++ Compile Error: c++: internal compiler error: Killed (program cc1plus)
- Python calls C to generate so library and reports an error: undefined symbol
- fatal error C1001: INTERNAL COMPILER ERROR