简体   繁体   中英

Error From Passing std::string Reference

This is probably really simple and I'm just being an idiot.

When I try to compile (Linux, 64bit, gcc) this:

namespace GUI {

class Manager
{
...
    private:
        bool AddElement(const std::string&, Element*);

        /// Friend functions
        friend void Element::AddToManager(const std::string&);
};

class Element
{
...
    private:
        void AddToManager(const std::string&);
        Manager* mGuiManager;
...
}

void Element::AddToManager(const std::string& rName)
{
    mGuiManager->AddElement(rName, this); // Error on this line
}

}

I get the error:

undefined reference to `GUI::Manager::AddElement(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, GUI::Element*)'

Where should I start to resolve this?

我对错误中的STL位分心,而忘了我已经注释掉了实际功能。

您需要在Element类中添加以下声明:

friend class Manager;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM