如何返回聚合在另一个类中的点对象?
如何返回聚合在另一个类中的点对象?我试图返回一个点对象,它是四元类的私有成员。我已经编写了该函数并且可以编译,但我不知道调用该函数的正确语法。
Point Quad::getA()
{
return Point a;
}
void Quad::check()
{
cout << this->getA(); //will not work
}
How do I return a point object aggregated in a another class? I'm trying to return a point object that's a private member of the quad class. I have written the function and it compiles, but I don't know the correct syntax to call that function.
Point Quad::getA()
{
return Point a;
}
void Quad::check()
{
cout << this->getA(); //will not work
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将起作用:
This will work:
return Point a;
是错误的。您可以创建一个对象然后返回,也可以在 return 语句本身中创建该对象。正确的语法:
return Point a;
is wrong. You either create a object and then return or have the object created in the return statement itself.Correct syntax:
在类内部
GetA() 函数中。
返回一个指针将是一个更好的解决方案。在程序的整个生命周期中维护单个指针将使开发人员更容易正确地销毁该指针。仅供参考 http://en.wikipedia.org/wiki/Singleton_pattern
对不起,我的错。心中有这个想法,但表达错误。
Inside class
In GetA() function.
Returning a pointer would be a better solution. Maintaining a single pointer throughout the lifetime of the program would make it easier for the developer to properly destroy the same. For reference http://en.wikipedia.org/wiki/Singleton_pattern
Sorry my bad. Had this in the mind but conveyed it wrong.