Nowe posty

xx Dystrybucja pod HP Omen (6)
Wczoraj o 23:30:08
xx [Poradnik] Wyszukiwanie Sterowników (2)
Wczoraj o 21:08:23
lamp Problem z Linux Lite po instalacji (0)
Wczoraj o 19:50:30
xx Ile pingwinów? (1)
Wczoraj o 08:59:24
xx konfiguracja pale moon (0)
2024-03-24, 21:53:42
xx Plasma 6 w Neonie ssie trochę mniej ... (10)
2024-03-23, 02:38:11
xx problem z instalacja sterowników do karty sieciowej (3)
2024-03-18, 18:10:16
xx Plik abc.001 (1)
2024-03-17, 17:48:27
xx Zlecę dopracowanie programu w MatLab (0)
2024-03-13, 15:28:40
xx Linux Mint 21.3 XFCE brak dźwieku po paru minutach (karta muzyczna zintegrowana) (5)
2024-03-12, 23:07:01

Autor Wątek: Przekazywanie zmiennej pomiędzy klasami  (Przeczytany 5851 razy)

KelThuzad

  • Gość
Przekazywanie zmiennej pomiędzy klasami
« dnia: 2016-11-17, 17:38:46 »

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

Filystyn

  • Gość
Odp: Przekazywanie zmiennej pomiędzy klasami
« Odpowiedź #1 dnia: 2016-12-05, 17:25:40 »
Zapisujesz zmienną w kasie. Zmienna jest publiczna. potem kopiujesz ją do drugiej zmiennej w klasie. i tyle.