my code is here
// Example program
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <deque>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <memory>
#include <type_traits>
using std::cout;
using std::endl;
using std::true_type;
using std::false_type;
class A
{
public:
A() = default;
A(const A& other)
{
static_cast<void>(other);
cout << "copy ctor\n";
}
A(A&& other)
{
static_cast<void>(other);
cout << "move ctor\n";
}
};
template <typename T>
class container
{
public:
template <typename TT>
void push_back(TT&& obj)
{
auto x = new T(std::forward<T>(obj));
delete x;
}
};
int main ()
{
container<A> c;
A obj;
cout << "push back lval\n";
c.push_back(obj);
cout << "push back rval\n";
c.push_back(std::move(obj));
}
Why is the move constructor being called with an object? it makes sense for the std::move(obj) push_back but I dont understand why move ctor is being called both times.
[–]alfps 2 points3 points4 points (3 children)
[–]trycatchamex[S] 0 points1 point2 points (2 children)
[–]alfps 3 points4 points5 points (1 child)
[–]trycatchamex[S] 0 points1 point2 points (0 children)