c++ member function hides global function

Issue

This Content is from Stack Overflow. Question asked by Immanuel Kant

This code snippet doesn’t compile:

struct M {
    int i;
    int j;
};

void f(M& m) {
    m.i++;
}

struct N {
    M m;
    void f(int i) {
        f(m); // compilation error
    }
};

clang says : No viable conversion from 'M' to 'int'
Seems my member function hides global function.

I changed the error line into ::f(m) to help name resolution, but still fails. Does it mean that in c++ member function, cannot call global overload function with same name but different parameter list?

How to fix this?
Thanks!



Solution

Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?