I'll use a basic class to define the behavior of the compiler as best as I know how to.
class Student sealed {
private:
std::string m_strFirstName;
std::string m_strLastName;
std::vector<unsigned short> m_vClassNumbers;
std::vector<std::string> m_vTeachers;
std::vector<unsigned short> m_vClassGrades;
public:
Student( const std::string& strFirstName, const std::string& strLastName );
std::string getFirstName() const;
std::string getLastName() const;
void setClassRoster( std::vector<unsigned short>& vClassNumbers );
std::vector<unsigned short>& getClassRoster() const;
void setClassTeachers( std::vector<std::string>& vTeachers );
std::vector<std::string>& getClassTeachers() const;
void setClassGrades( std::vector<unsigned short>& vGrades );
std::vector<unsigned short>& getGrades() const;
// Notice That These Are Both Commented Out So The Compiler Will
// Define These By Default. And These Will Make Shallow / Stack Copy
// Student( const Student& c ); // Default Defined
// Student& operator=( const Student& c ); // Default Defined
};
The version of this class with its declaration by default will construct both a copy constructor and an equal operator.
class Student sealed {
private:
std::string m_strFirstName;
std::string m_strLastName;
std::vector<unsigned short> m_vClassNumbers;
std::vector<std::string> m_vTeachers;
std::vector<unsigned short> m_vClassGrades;
public:
Student( const std::string& strFirstName, const std::string& strLastName );
std::string getFirstName() const;
std::string getLastName() const;
void setClassRoster( std::vector<unsigned short>& vClassNumbers );
std::vector<unsigned short>& getClassRoster() const;
void setClassTeachers( std::vector<std::string>& vTeachers );
std::vector<std::string>& getClassTeachers() const;
void setClassGrades( std::vector<unsigned short>& vGrades );
std::vector<unsigned short>& getGrades() const;
private:
// These Are Not Commented Out But Are Defined In The Private Section
// These Are Not Accessible So The Compiler Will No Define Them
Student( const Student& c ); // Not Implemented
Student& operator=( const Student& c ); // Not Implemented
};
Where the second version of this class will not since I declared both of them as being private!
This is probably the best way I can demonstrate this. I only showed the header file interface to this class since the c++ source or code to be compiled is not of a concern. The difference in how these two are defined during the Pre-Compile Stage dictates how the Compiler Will Work before it begins to compile the source code into object code.
Keep in mind though that the standard library strings & containers do implement their own Copy Constructor & Assignment Operators! But the same concept applies to the behavior of the compiler if a class has basic types such as int, float, double, etc. So the compiler will treat a Simple class in the same manner according to its declaration.
class Foo {
private:
int m_idx;
float m_fValue;
public:
explicit Foo( float fValue );
// Foo( const Foo& c ); // Default Copy Constructor
// Foo& operator=( const Foo& c ); // Default Assignment Operator
};
Second Version
class Foo {
private:
int m_idx;
float m_fValue;
public:
explicit Foo( float fValue );
private:
Foo( const Foo& c ); // Not Implemented
Foo& operator=( const Foo& c ); // Not Implemented
};
The compiler will treat this class in the same manner; it will not define either of these since they will not be implemented due to being declared as private.