更改函数内部的对象
change the objects inside functions
我有一个函数,它有两个参数,都是对象。我在函数中改变了这些对象,之后我需要看到这些改变。但是指针不起作用。任何想法?
void foo(apple &a,apple &b)
{
//change a and b
}
main()
{
apple a,b;
foo(a,b);
//a and b are the same as befor calling foo `
}
谢谢。
你的意思是改变你传递的类的方法吗?如果你是这个意思,你需要使用'->'。
class apple {
public:
int weight;
}
void foo(apple *a,apple *b) {
a->weight = b->weight;
}
main() {
apple a,b;
foo(&a,&b);
}
相关文章:
- 如何从传递到对象的对象内部访问对象的类属性?
- 对象内部对象的重载功能
- 为什么我不能更改实例化对象内部的向量?
- 对象内部有大量数据容器,实现更高效的对象交换
- 微机器人 - 检查点是否在对象内部
- C++:访问对象内部子对象的方法
- 如果访问对象,则指向的对象内部的指针会更改内存位置
- shared_ptr - 从包含的对象内部访问
- 如何创建功能以用受保护或私人侵犯的对象在对象内部操纵对象
- 如何从对象内部的 typedef 获取模板参数类型
- DirectX 11渲染对象内部
- 引用对象内部的指针
- 访问对象内部的指针
- 访问检测到的对象/c++内部的像素值
- 如何在linux x64上创建共享库对象,该对象内部使用C++异常,并且可以在旧平台上运行
- OpenGL检测单击另一个对象内部的对象
- 如何在类对象内部分配数组
- 在基类对象内部创建派生类对象
- 多态对象内部的C++引用
- 在C++中,如何在没有动态分配(即NEW)的情况下将对象初始化为对象内部的指针