Skip to content

Instantly share code, notes, and snippets.

@vasalf
Created December 6, 2019 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasalf/d2d4447038d4e4a6a052cb5da8c96cfc to your computer and use it in GitHub Desktop.
Save vasalf/d2d4447038d4e4a6a052cb5da8c96cfc to your computer and use it in GitHub Desktop.
Внутренний приватный класс
#include <aclass.hpp>
A::A() {
x = 30;
}
int A::f() {
x += 10;
b.f();
return x + b.getX();
}
A::B::B() {
x = 138;
}
void A::B::f() {
x++;
}
int A::B::getX() {
return x;
}
#pragma once
class A {
private:
class B {
public:
B();
void f();
int getX();
private:
int x;
};
public:
A();
int f();
private:
B b;
int x;
};
#include <aclass.hpp>
#include <iostream>
int main() {
A a;
std::cout << a.f() << std::endl;
}
all: main
bin:
mkdir bin
bin/aclass.o: src/aclass.cpp | bin
g++ -c -g -Iinclude -std=c++11 src/aclass.cpp -o bin/aclass.o
bin/main.o: src/main.cpp | bin
g++ -c -g -Iinclude -std=c++11 src/main.cpp -o bin/main.o
main: bin/aclass.o bin/main.o
g++ bin/aclass.o bin/main.o -o main
clean:
rm -Rf bin main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment