samedi 28 avril 2018

c++ function is publicly callable despite explicitly declared private

I am currently investigating why I am able to call a private function from a context where it should not be accessible from. I have already narrowed it down to a very simple example, but I am still unable to identify the issue.

LIVE example

This is my narrowed down version:

template<typename From, typename To>
concept bool ConvertibleNoNarrow = requires(From f, To t) {
    t = { f };
};

template<typename T>
class Wrapper {
    T t;
public:
    Wrapper(ConvertibleNoNarrow<T> u) : t(u) { }

private:
    // should be PRIVATE
    void operator()() { }
};

int main() {
    Wrapper<long> w(1);

    // should not be able to call this!
    w();
}

Aucun commentaire:

Enregistrer un commentaire