Is this movement and copy of the wrapper sound complete?

I just made a wrapper for move and copy operations to enter into the code to see what is called in the case of the default implementation. I am getting closer to understanding what is called, but I would like to double-check the time.

I'm not sure if method 1 of is using T::T;better for constructors than method 2 to forward arguments like unique_ptr? I found it in this thread. Forwarding all constructors in C ++ 0x

In the move constructor and assignment, I use std::moveto go to the superclass. Should it be std::forward, and if so, how? I get errors trying to use it.

#ifndef MOVECOPY_OBSERVER_H
#define MOVECOPY_OBSERVER_H

#include <iostream>

template<class T>
class MoveCopyObserver : public T {
public:
    //1: Use "using" for constructors 
    //From /questions/66334/forwarding-all-constructors-in-c0x
    using T::T;

    //2: Forward all args, unique_ptr style.
    /*
    template<typename... Args>
    MoveCopyObserver(Args&&... args) 
        : T(std::forward<Args>(args)...) 
    {
    };*/

    // *************************************************************************
    virtual ~MoveCopyObserver() = default;


    // *************************************************************************
    MoveCopyObserver(const MoveCopyObserver& other)
        : T(other)
    {
        std::cout << "Copy constructor " << typeid(T).name() << std::endl;
    }


    // *************************************************************************
    MoveCopyObserver(MoveCopyObserver && other)
        : T(std::move(other)) //3: std::forward instead?
    {
        std::cout << "Move constructor " << typeid(T).name() << std::endl;
    }


    // *************************************************************************
    MoveCopyObserver& operator=(const MoveCopyObserver& other)
    {
        T::operator=(other);
        std::cout << "Copy assignment " << typeid(T).name() << std::endl;
        return *this;
    }


    // *************************************************************************
    MoveCopyObserver& operator=(MoveCopyObserver&& other)
    {
        T::operator=(std::move(other)); //3: std::forward instead?
        std::cout << "Move assignment " << typeid(T).name() << std::endl;
        return *this;
    }
};


#endif //MOVECOPY_OBSERVER_H

Usage will be on the stack or through smart pointers, for example:

class A {
public:
    A(std::string ss)
    {
        s = ss;
    }

    void f()
    {
        std::cout << "\"" << s << "\"" << std::endl;
    }

private:
    std::string s;
};

A a("Test instance");
a.foo();

MoveCopyObserver<A> b("Another instance");
b.foo();
+4

All Articles