C++:求两数之和?

2024-11-30 09:42:52
推荐回答(1个)
回答1:

  1. #include

  2. using namespace std;

  3. class Test

  4. {

  5. private:

  6. int a;

  7. int b;

  8. public:

  9. Test(int a, int b)

  10. {

  11. this->a = a;

  12. this->b = b;

  13. }

  14. int add();

  15. };

  16. int Test::add()

  17. {

  18. return a+b;

  19. }

  20. int main()

  21. {

  22. Test t1(2,3);

  23. cout << t1.add() << endl;

  24. Test *t2 = new Test(8,9);

  25. cout << t2->add() << endl;

  26. delete t2;

  27. return 0;

  28. }