彼此的两个班级做得对 [英] Two classes in each other done right

查看:104
本文介绍了彼此的两个班级做得对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

首先我想道歉,如果之前有问过这个问题,但我找不到答案:(。







我需要知道如何将两个类作为变量彼此相对。我知道我必须有前向引用和变量但有人可以告诉我深层复制构造函数,operator =和dereference函数应该在那个例子中应该是什么样的。有时候我会指点一点点。



Todor

Hi every one.
First I want to apologize if that question was asked before but I couldn't find the answer for it :(.



I need to know how can I have two classes as variables in each other. I know I have to have forward reference and the variables to be pointes. But can someone show me how should a deep copy constructor, operator= and dereference function should look like in that instance. Pointers for me a little bit hard sometimes.

Todor

推荐答案

请参阅 https:// msdn.microsoft.com/en-us/library/4a1hcx0y.aspx [ ^ ]。


根据你的代码判断,你不了解指针的基础知识。请参考这篇文章:初学者指针指南 [ ^ ]



另外,你不必要地复制对象。指针(双关语不是意图)就是你不需要复制;相反,你从不同的位置引用相同的对象。只有当您想在本地更改对象并且不希望该更改影响原始对象时,才需要复制。
Judging by your code you don't understand the basics of pointers. Please consult this article: A Beginner's Guide to Pointers[^]

Also, you are copying objects needlessly. The point of pointers (pun not intended) is that you don't need to copy; instead you refer to the same object from different locations. A copy is only needed if you want to change the object locally and don't want that change to affect the original object.


这篇关于彼此的两个班级做得对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆