传入C++函数的对象值
Object Value Passing in C++ functions
#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中尝试过这段代码。 但它不起作用。我也没有收到任何错误。
我越来越"c4.display Thread1:breakpoint 1.1"
谁能告诉我我在这里做错了什么?
我正在做的是将两个对象First
和Second
值一起添加并Display
。
我也在c4.display()上检查了信息我得到了这个
c4 的打印说明: (校准) c4 = (x = 30, y = 70) (lldb)
如果你在顶部添加#include <iostream>
,它将编译并运行良好。
相关文章:
- 如何创建对象函数指针C++映射?
- 为什么我可以改变常量对象中的成员变量,这是返回常量对象函数的结果?
- 如何将对象函数的实例传递给另一个函数
- 调用模板函数的问题"No matching function for call"参数:迭代器、对象函数
- makefile对我的名称空间对象/函数/构造函数的不确定引用
- 将对象函数转换为函数指针
- 非对象函数/类函数C++
- 线程对象函数 C++
- C 将成员对象函数分配给类成员功能
- 使用基本指针调用派生对象函数
- 可以(通过编译器)使用多少个线程来初始化全局对象(函数main之前)
- C++类对象函数
- 对对象::函数的未定义引用
- 无法弄清楚将多个对象函数作为单独的线程调用的语法
- 在提升作用域出口中调用对象函数
- 使用基指针来使用派生对象函数
- 在for_each lambda 中调用对象函数
- C++:: 模板函数 - 从对象函数获取对象的地址
- Qt5 未解析的外部静态元对象函数
- 通过变量使用对象和对象函数