1/22
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
How is a method implemented in C++
Usually outside of the class, using the scope resolution operator ::
Car::Car() {}What is the scope resolution operator ::
Links a method implementation to its class
What goes in the header file (.h)
Contains class definitions
What goes in the source file (.cpp)
Contains method implementations and code
What are the three types of scope that C++ structures can be defined as
private
public
protected — private but accessible to subclasses
how do you define a class in C+ in the header file
class Car{
private:
int milesDriven;
int age;
public:
Car();
void drive(int miles);
};how do you initialise an object in C++
Car::Car() {
milesDriven = 0;
age = 10;How do you define a class in the source file in C++
void Car::drive(int miles) {
milesDrive += miles;
}What is a stack-allocated object
Declared like normal variables, and automatically destroyed when scope ends.
What is a heap-allocated objecet
Created with new, returned as a pointer, and must be deleted manually.
How does a pointer work in C++
Declared with *, accessed with →
How does references to objects work in C++
Declared with & , must be initialised, immutable and accessed with.
What pass-by method does C++ use
Pass by value (copies of variables)
what is <iostream> in c++
input/output streams (replaces stdio.h)
What is <string> in C++
The string class (wrapper around char arrays)
How do strings work in C++
C-style string (char *)
high-level (std::string)
what methods does string have
length
find
substr
append
replace
how does ‘cin’ work in C++
reads input
int age;
std::cin >> age;how does ‘cout’ work in C++
std::cout << "hello, " << name << "!";what is a namespace
they group related identifiers (classes, functions, variables) to avoid name collisions. the standard library lives in the std namespace.
How do you access a namespace member
:: notation
how do you define a namespace
namespace MyMath {
int add(int a, int b){
return a + b;
}
}how do you use a method defined inside a namespace
int x = MyMath::add(3, 5);