nin*_*pig 1 c++ class shared-ptr
我试图第一次使用共享指针,我遇到了一个问题,我无法从指针访问Element的成员函数.我已经看过网络上的例子了,似乎应该可以访问Element的功能,但我怀疑我在设置指针时做错了什么,但我无法解决问题.
如何从shared_ptr访问Element中的公共成员函数?(我正在使用Xcode 5.1.1)
#include <memory>
#include <iostream>
class Element
{
private:
std::string name;
std::shared_ptr<Element> * firstChild;
std::shared_ptr<Element> * lastChild;
std::shared_ptr<Element> * nextSibling;
public:
void addChild(std::shared_ptr<Element> * child)
{
if (lastChild != nullptr) {
lastChild->setNextSibling(child); //Error: No member named 'setNextSibling' in 'std::__1::shared_ptr<Element>'
lastChild = child;
}
else {
firstChild = lastChild = child;
}
}
void setNextSibling(std::shared_ptr<Element>* p)
{
nextSibling = p;
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1842 次 |
| 最近记录: |