[ create a new paste ] login | about

Link: http://codepad.org/3YTqEF2O    [ raw code | output | fork ]

johannes - C++, pasted on Sep 7:
class K
{
public:
    K() {}
    ~K() {}

    inline void setSomeStr(const std::string &str) { m_someStr = str; }
    inline const std::string &someStr() const { return m_someStr; }

private:
    std::string m_someStr;
};

int main()
{
    K k;
    k.setSomeStr("banan");
    std::cout << k.someStr() << "\n";

    std::string &ss = const_cast<std::string&>(k.someStr());

    ss = "hello";

    std::cout << k.someStr() << "\n";

}


Output:
1
2
banan
hello


Create a new paste based on this one


Comments: