Skip to content
  • Constructors · OOPs

Constructors

LearnViaNotes @learnvianotes· 1 min read

A special method invoked automatically when an object is created. Used for initialization. Never has a return type.

Types of constructors

Constructor overloading

Shallow vs Deep Copy

C++
// Deep copy — allocate new memory

Teacher(Teacher &orig) {

  name = orig.name;

  data = new int[size];  // new allocation!

  copy(orig.data, orig.data+size, data);

}

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report