使用构造函数初始化类中的指针 [英] initialize a pointer in a class with constructor
本文介绍了使用构造函数初始化类中的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的专辑类:
I have an Album class like this:
class Album
{
.
.
.
}
和这样的Song类:
and a Song class like this:
class Song
{
public:
Song(Album* _album): album(_album) {}
private:
Album* album;
}
如何让每首歌指向其专辑?
谢谢
how can I make every Song to point to its Album?
thanks
推荐答案
由于您的构造函数,它已经指向Album
对象,并使用字段专辑
。
-SA
It already points to theAlbum
object, due to your constructor, with the use of the fieldalbum
.
—SA
这篇关于使用构造函数初始化类中的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文