C++ Classes Flashcards
Though functionally identical, what is the biggest difference between structs and classes?
Class defaults to private, while struct defaults to public
What is the difference in use case between structs and classes
Classes are best for data abstraction and inheritance, while structs are best used for data grouping and access.
What are the two basic constructors?
Default (no args) and with input
What is the abbreviation of Constructor?
CTOR
What are the non-basic Constructors?
- Copy
- Assignment
- Move
- Move Assignment
What is Uniform Initialization Syntax
The standard ways of constructing objects and variables in c++
What are the Uniform initialization Syntax ctors?
Default, Empty, Initializer List, Assignment
What is the following Ctor? string x;
default
What is the following Ctor? string x{};
Empty
What is the following Ctor? string x{“string”};
Initializer List
What is the following Ctor? string x = “string”;
Assignment
How do you define a Class?
class MyClass{
//private fields
int num1;
public:
MyClass() {num1 = 1;}
int get_num1() { return this->num1;}
};
How do you define a Struct?
struct MyStruct{
//public fields
MyStruct() {num1 = 1;}
int get_num1() { return this->num1;}
private:
int num1;
};
What is the “this” keyword?
It is a pointer to the current object
What is the syntax for using the “this” keyword?
this->