Implicit vector type cast for a custom class

Viewed 31

I have the following class:

class A
{       
    public: 

        A();
        A(uint64_t A);
        A(const A&) = default;

        operator uint64_t&() { return m_A; }
        operator const uint64_t& () const { return m_A; }

    private:

        uint64_t m_A;
};

With the following functions:

void Foo(const uint64_t& value);
void Bar(const std::vector <uint64_t>& value);

And as i have the () operator overload, when doing the following:

A a;

Foo(a);

The Foo(a); function call gets expectedly and correctly implicitly cast into

Foo(const uint64_t & a);

But when doing the following:

std::vector <A> aVector;

Bar(aVector);

it does not get implicitly cast into

Bar(const std::vector <uint64_t> & a);

which I want to happen.

What do I need to add so the std::vector <A> aVector gets implicitly cast into const std::vector <uint64_t> & aVector ?

0 Answers
Related