Using gcc version 4.8.2:
I'm running into an issue where the const qualifier on my parameters is disappearing when I compile my code. Here is an example:
main.cc:
#include <iostream>
class Base
{
public:
virtual int getSum( const int number ) = 0;
};
class Derived : public Base
{
public:
Derived( const int& num )
: _myNumber( num )
{}
virtual int getSum( const int number )
{
return _myNumber + number;
}
private:
int _myNumber;
};
int main( int argc, const char* argv[] )
{
Base *b = new Derived( 2 );
std::cout << b->getSum( 3 ) << "\n";
}
Compiled like so:
g++ main.cc -o const_test
When I run nm:
nm const_test | c++filt | grep getSum
I get the following output:
0000000000400b60 W Derived::getSum(int)
Why does the const disappear from my function when it compiles?