最後我是用這樣的寫法
a.cpp
#include "t.h"
int main(){
TT *a = new TT(4);
a->p();
delete a;
return 0;
}
t.h
#ifndef TEST
#define TEST
class TT{
public:
TT(int s = 2);
void p ();
int s;
};
#endif
t.cpp
#include "t.h"
#include <iostream>
using namespace std;
TT::TT(int s){
this->s = s;
}
void TT::p(){
cout << this->s << endl;
}
這樣子沒有引數的時候會輸出預設的2
不知道這樣的寫法有無問題
盼高手指正