Passing const CName as this argument discards qualifiers

Posted by Geno Diaz on Stack Overflow See other posts from Stack Overflow or by Geno Diaz
Published on 2012-09-07T09:29:58Z Indexed on 2012/09/07 9:38 UTC
Read the original article Hit count: 360

Filed under:
|
|
|

I'm having trouble with passing a constant class through a function.

 // test the constructors
    auto    CName       nameOne("Robert", "Bresson");
    const   CName       nameTwo = nameOne;
    auto    CName       nameThree;

    // display the contents of each newly-constructed object...

    // should see "Robert Bresson"
    cout << "nameOne = ";
    nameOne.WriteFullName();
    cout << endl;

    // should see "Robert Bresson" again
    cout << "nameTwo = ";
    nameTwo.WriteFullName();
    cout << endl;

As soon as the compiler hits nameTwo.WriteFullName() I get the error of abandoning qualifiers. I know that the class is a constant however I can't figure out how to work around it.

The function is in a header file written as so:

void    const WriteFullName(ostream& outstream = cout)
{
    outstream << m_first << ' ' << m_last;
}

I receive this error when const is put in back of the function header

main.cpp:(.text+0x51): undefined reference to CName::CName()' main.cpp:(.text+0x7c): undefined reference toCName::WriteFullName(std::basic_ostream >&) const' main.cpp:(.text+0xbb): undefined reference to CName::WriteFullName(std::basic_ostream<char, std::char_traits<char> >&) const' main.cpp:(.text+0xf7): undefined reference toCName::WriteFullName(std::basic_ostream >&) const' main.cpp:(.text+0x133): undefined reference to operator>>(std::basic_istream<char, std::char_traits<char> >&, CName&)' main.cpp:(.text+0x157): undefined reference tooperator<<(std::basic_ostream >&, CName const&)' main.cpp:(.text+0x1f4): undefined reference to operator<<(std::basic_ostream<char, std::char_traits<char> >&, CName const&)' main.cpp:(.text+0x22b): undefined reference tooperator<<(std::basic_ostream >&, CName const&)' main.cpp:(.text+0x25f): undefined reference to operator<<(std::basic_ostream<char, std::char_traits<char> >&, CName const&)' main.cpp:(.text+0x320): undefined reference tooperator<<(std::basic_ostream >&, CName const&)' main.cpp:(.text+0x347): undefined reference to `operator>>(std::basic_istream >&, CName&)'

© Stack Overflow or respective owner

Related posts about c++

Related posts about class