Tsallaka zuwa abun ciki
Justice Tech School

Classes

A class has data and member functions. public and private control access.

Example
#include <iostream>
#include <string>

class Person {
  std::string name; int age;
public:
  Person(std::string n, int a) : name(n), age(a) {}
  std::string describe() const { return name + " (" + std::to_string(age) + ")"; }
};

int main() {
  Person p("Ada", 30);
  std::cout << p.describe() << "\n";
  return 0;
}

Result

Ada (30)

Exercise

Private section.

:

Quiz Test

Default access in a class?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.