两数相加,运行的时候显示下面的情况
helloworld.cpp
#include<iostream>
#include "hello.h"
using namespace std;
int main()
{
sum m(1,2);
}
hello.h
#ifndef MYTIME1_H_
#define MYTIME1_H_
class sum{
private:
int x;
int y;
public:
sum();
sum(int a,int b=0);
void add();
};
#endif
hello.cpp
#include <iostream>
#include "hello.h"
using namespace std;
sum::sum()
{
x=y=0;
}
sum::sum(int a,int b)
{
x=a;
y=b;
}
void sum::add()
{
cout<<"the sum is "<<(x+y);
}