[Solved] C++: How do I create a vector of objects and insert an object in 3rd place? [closed]


std::vector::insert accepts a const reference to value type, which can only be assigned to other const references.

Your operator=, though, accepts a non-const reference, so it cannot be used in overload resolution.

General solution: Make operator= accept a const reference.

Specific solution for your case: Just drop your custom operator= entirely! There are no types involved that require explicit manual memory management (std::string does so fine on its own, the other members are primitive types anyway), so the operator generated by default will be absolutely fine.

std::copy not working: std::ostream_iterator uses operator<< to print values to the stream. There is no such operator for your type – you might convert your info function into one:

//void info() 
friend std::ostream& operator<<(std::ostream& s, MobilniTelefon const& t)
{
    // output t to s as you just as you did previously this to std::cout
    return s;
}

Instead of calling info, you could now do

MobilniTelefon t;
std::cout << t;

Apart from, you are using wrong template specialisation, should be:

//std::ostream_iterator<int> output(std::cout, " ");
std::ostream_iterator<MobilniTelefon> output(std::cout, " ");

2

solved C++: How do I create a vector of objects and insert an object in 3rd place? [closed]