我有一個包含以下爲什麼我的程序打印默認構造函數?
class newpoint
{
public:
newpoint();
newpoint(int num1, int num2);
double average(int num11, int num22);
};
和a.cpp文件與newpoint.h
#include "newpoint.h"
#include <iostream>
using namespace std;
newpoint::newpoint()
{
cout << "This is the default constructor talking " << endl;
}
newpoint::newpoint(int number1, int number2){
int sum = number1 + number2;
cout << sum << endl;
}
double newpoint::average(int number11, int number12){
double avg = (number11 + number12)/2;
return avg;
cout << "the average is" << avg << endl;
}
和具有.h文件作爲頭,並計算出SOURSE文件頭文件從newpoint.cpp文件,稱他們如下
#include <iostream>
#include "newpoint.h"
using namespace std;
int main(){
int num4, num5;
newpoint dag;
//newpoint dag2(2,3);
//cout << "enter a number " << endl;
//cin >> num4;
//cin >> num5;
newpoint ave;
ave.average(2,5);
return 0;
}
爲什麼我的程序打印默認構造函數研究所的 功能ead的平均功能是 ?
你覺得'newpoint dag;'是做什麼的? –
構造函數在創建對象時運行,並且在顯示值之前從函數返回。 –
我知道它會打印默認承包商,但是dag.average呢? –