C++ const question

后端 未结 7 1600
遥遥无期
遥遥无期 2020-12-20 16:58

If I do this:

// In header 
class Foo {
void foo(bar*);
};

// In cpp
void Foo::foo(bar* const pBar) {
//Stuff
}

The compiler does not comp

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-20 17:33

    This is simpler to understand with a variable type other than a pointer. For example, you can have the following function declaration:

    void foo( int i );
    

    The definition can look like this:

    void foo( const int i ) { ... }
    

    Whether the variable 'i' is const or not on the definition side is an implementation detail. It has no impact for the clients of that function.

提交回复
热议问题