Код: Выделить всё
#ifndef MYSOLVER_H
#define MYSOLVER_H
class mySolver {
public:
bool verbose = false;
void solve();
};
#endif // MYSOLVER_H
Код: Выделить всё
#include "mySolver.h"
void mySolver::solve()
{
printf("verbose = %d\n", verbose);
}
Код: Выделить всё
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include "mySolver.h"
class testClass {
private:
mySolver MySolver;
public:
void run();
};
#endif // TESTCLASS_H
Код: Выделить всё
#include "testClass.h"
#include "mySolver.h"
void testClass::run()
{
MySolver = mySolver();
printf("verbose = %d\n", MySolver.verbose); // Prints 0
MySolver.verbose = true;
printf("verbose = %d", MySolver.verbose); // Prints 1
MySolver.solve(); // Prints 0
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -peristing
Мобильная версия