I'm looking to pass an object (called Orthography) into a function so I can get at the wstring m_Name variable it has. Much of the advice I've been given on this forum has centered around using const and & when passing something into a function. So I'm looking to pass an Orthography object into a function via "const Orthography&". But when I go that route, I get a red line under my object name and when I hover over it, it says "the object type has qualifiers that are not compatible with the member function." When I Google that error, what I've found refers to using const but I haven't found anything that I can apply to my situation.
I get a red line under "orthography" in that line. I'm not sure what is going on or how to approach this. The red line disappears if I don't use const and & but from what I've been reading, it is good practice to use them.
'orthography' is a const reference. By being const, it means that you cannot modify it. The compiler does not know that 'GetCharacterMatches' will not modify the object, therefore it gives you that error.
You need to make that function const to tell the compiler it's okay to call it with const objects. You do this by putting a const after the function parameter list:
1 2 3 4
whatever_type Orthogrophy::GetCharacterMatches() const // <- the const here makes it a const member function
It is good practice to do this with all member functions that do not make any changes to the object. IE: all getters. (unless you have a good reason not to -- which is sometimes the case)