[問題] 類別分.h.cpp分開寫後碰到的問題
小的是C++新手,一直沒有把類別用.h和.cpp分開寫的習慣
今天小試了一下後碰到了一個問題
/* main.cpp*/
#include "common.h"
#include "calculator.h"
int main(int argc, char *argv[])
{ calculator cook;
cook.add(2);
cook.sub(2);
cout<<1<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
/* common.h*/
#ifndef common_h
#define common_h
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
#endif
/* calculator.h */
#ifndef calculator_h
#define calculator_h
class calculator{
private:
protected:
public:
void add(int data);
void sub(int data);
};
#endif
/* calculator.cpp */
#include "common.h"
#include "calculator.h"
calculator::calculator(){cout<<"welcome"<<endl;}
void calculator::add(int data){cout<<data<<endl;}
void calculator::sub(int data){cout<<data+1<<endl;}
________________________________________________________________
假如calculator.cpp沒有建構者函式的話可以順利編譯
但是有建構者函式卻不能順利編譯,所以不知道問題出在哪
可以請過來人解答一下嗎,謝謝
________________________________________________________________
環境
devC++
原因
3 C:\Documents and Settings\user\桌面\新資料夾\calculator.cpp definition of
implicitly-declared `calculator::calculator()'
3 C:\Documents and Settings\user\桌面\新資料夾\calculator.cpp declaration of
`calculator::calculator()' throws different exceptions
3 C:\Documents and Settings\user\桌面\新資料夾\calculator.h than previous
declaration `calculator::calculator() throw ()'
C:\Documents and Settings\user\桌面\新資料夾\Makefile.win [Build Error]
[calculator.o] Error 1
不好意思漏掉了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.47.229.212
→
09/08 13:26, , 1F
09/08 13:26, 1F
※ 編輯: yahooc 來自: 114.47.229.212 (09/08 13:27)
→
09/08 13:27, , 2F
09/08 13:27, 2F
→
09/08 13:30, , 3F
09/08 13:30, 3F
→
09/08 13:33, , 4F
09/08 13:33, 4F
→
09/08 13:35, , 5F
09/08 13:35, 5F
→
09/08 13:38, , 6F
09/08 13:38, 6F
→
09/08 13:39, , 7F
09/08 13:39, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章