#include <string>
#include <iostream>
#include <fstream>
using namespace std;
class cal
{
int x, y;
public:
void set(int a, int b)
{
x = a;
y = b;
}
cal add(cal c1, cal c2)
{
cal temp;
temp.x = c1.x + c2.x;
temp.y = c1.y + c2.y;
return temp;
}
void display()
{
cout << x << y; //display output
}
};
int main()
{
cal c1, c2, c3, c4;
c1.set(10, 30);
c2.set(20, 40);
c4 = c3.add(c1, c2);
c4.display();
}
我已经在Xcode中试过这段代码。但它不起作用。我也没有得到任何错误。对象值通过C++函数
我越来越"c4.display Thread1:breakpoint 1.1"
能取悦任何人告诉我,我做错了什么吗?
我在做什么是将两个对象First
和Second
值加在一起,Display
。
而且我在c4.display检查信息() 和即时得到C4的这个
打印说明:(CAL)C4 =(X = 30,Y = 70)(LLDB)
这段代码如何在没有包含的情况下编译?并且请更好地格式化代码。 –
PaulMcKenzie
它在代码中。但我没有在这里添加它们。因为我认为它不是很重要。@ PaulMcKenzie –