I declared a class template as follows:
template<typename T>
class C{
public:
C(T&,
shared_ptr<C<T>>&
);
// rest of the public interface
private:
T& rData;
shared_ptr<C<T>>& rP;
};
Subsequently, I defined the template constructor as:
template<typename T> C<T>::C(T& rDataArg,
shared_ptr<C<T>>& rPArg
):rData(rDataArg),
rP(rPArg)
{}
For the above definition I got the following -Wreorder
warning from the g++ compiler:
warning: field 'rData' will be initialized after field 'rP' [- Wreorder]
I reversed the order of initialization in my constructor definition and the warning disappeared.
Since both the members of the template class are references, I am curious about why the initialization in the constructor should adhere to the order specified by the compiler.
Please share your thoughts.