I usually see the syntax = default used in the header. I understand that this is the same as if the functions are explicitly implemented in the header, see below Foo .
foo.h
#pragma once class Foo { public: Foo() = default; Foo(const Foo& other) = default; };
Out of curiosity, can = default be used in source files as follows?
bar.h
#pragma once class Bar { public: Bar(); Bar(const Bar& other); };
Bar.cpp
#include "Bar.h" Bar::Bar() = default; Bar::Bar(const Bar&) = default;
As far as I know, this is equivalent to explicitly implementing the functions in the cpp file.
The above Bar example is compiled using gcc-5.1 , but does this standard allow this use?
As an aside, are there any advantages to using = default in the source file compared to the header?
source share