MAG
MAG

Reputation: 3075

'const' qualifiers cannot be applied to 'std::vector<long unsigned int>&'

I had a c++11 project on linux where i used the following signature which fails to compile on linux but compiles on windows

Error:

error: 'const' qualifiers cannot be applied to 'std::vector<long unsigned int>&'

error: 'const' qualifiers cannot be applied to 'std::map<long unsigned int, long unsigned int>&'

Function was

    bool debugGlobalDs(std::vector<size_t> & const elementIds ,
 std::map<long unsigned int, long unsigned int>& const mapElementIdToGlobalIndex)
    {
    ....
    return true
    }

Why cant I use const qualifier here? Once I remove it, it compiles fine on Linux too.

Upvotes: 0

Views: 2440

Answers (1)

P.W
P.W

Reputation: 26800

The const is in the wrong place. It should be const std::vector<size_t>& elementIds.
This means that the function is not allowed to change elementIds.

The same is the case with the map as well.
It should be const std::map<long unsigned int, long unsigned int>& mapElementIdToGlobalIndex

Where const is placed in the OP marks the reference as const. As references cannot be changed anyway there is no need to do this.

Upvotes: 3

Related Questions