Przekazywanie zmiennej pomiędzy klasami

0
menu.choice.h
#ifndef MENU_CHOICE_H
#define MENU_CHOICE_H
class Menu_choice
{
private:
    int choice = {};
public:
    Menu_choice();
};
#endif // MENU_CHOICE_H

manu_choice.cpp

 #include "menu_choice.h"
#include <iostream>
#include <limits>
Menu_choice::Menu_choice()
{
    std::cout << "====================================================" << std::endl;
    std::cout << "=====Wybierz jedna z opcji ktora Cie interesuje=====" << std::endl;
    std::cout << "================1)Platnosc gotowka: ================" << std::endl;
    std::cout << "=================2)Platnosc karta: =================" << std::endl;
    std::cout << "=================3)Wplata na konto: ================" << std::endl;
    std::cout << "========4)Pokaz dostepne sierodki z budzetu: =======" << std::endl;
    std::cout << "==5)Pokaz wszystkie transakcje z danego miesiaca: ==" << std::endl;
    std::cout << "====================================================" << std::endl;
    std::cin >> choice;
    std::cout << "to jest choice: " << choice << std::endl;
}

transaction.h

 #ifndef TRANSACTION_H
#define TRANSACTION_H
#include "menu_choice.h"
class transaction
{
public:
    transaction();
};
#endif // TRANSACTION_H

transaction.cpp

 #include "transaction.h"
#include "menu_choice.h"
#include <iostream>
transaction::transaction()
{
    std::cout << "to jest wybor: " << Menu_choice.choice << std::endl;
}

main.cpp

#include "open_file.h"
#include "get_system_clock.h"
#include "menu_choice.h"
#include "transaction.h"
#include <iostream>
#include <fstream>
#include <chrono>
#include <ctime>
 
//extern double budget;
int main()
{
    using std::chrono::system_clock;
 
    Open_file my_file;
    std::cout << "to jest budzet: " << my_file.get_budget() << std::endl;
    std::cout << "to jest ssm: " << my_file.get_smart_saver_mateusz() << std::endl;
    std::cout << "to jest ssj: " << my_file.get_smart_saver_justyna() << std::endl;
 
    Get_system_clock time_now;
 
    Menu_choice menu;
    transaction kkk;
 
    return 0;
}

tak jak w temacie jak mogę przenieść zmienną choice z klasy menu_choice mogę wykorzystać w klasie transaction.h

0
  1. Dodać gettera do klasy Menu_choice zwracającego wartość pola choice i z niego skorzystać?
  2. Zaprzyjaźnić obie klasy?

Poza tym zrobić osobną funkcję wypisującą menu i obsłużyć wypadek gdy użytkownik wpisze jakąś bzdurę.
Przecież nie będziesz tworzył dziesięciu obiektów, bo do klawiatury dopadł się "yeti".

0 użytkowników online, w tym zalogowanych: 0, gości: 0