Nowe posty

xx Problem ze sterownikami. (5)
2024-04-13, 21:25:16
xx Instalacja xfce4 (2)
2024-04-13, 16:20:17
xx Serie kompilacji bez instalacji dla “emerge” w Gentoo (2)
2024-04-08, 18:40:04
xx Plasma 6 w Neonie ssie trochę mniej ... (17)
2024-04-05, 10:03:46
xx Problem z Linux Lite po instalacji (3)
2024-04-03, 14:23:40
xx Jak właczyć num locka przy starcie systemu debian 12? (12)
2024-04-02, 17:43:54
xx Brak dźwieku w systemie. (5)
2024-04-02, 16:13:41
xx Dystrybucja pod HP Omen (7)
2024-03-29, 11:33:05
xx [Poradnik] Wyszukiwanie Sterowników (2)
2024-03-27, 21:08:23
xx Ile pingwinów? (1)
2024-03-27, 08:59:24

Autor Wątek: Przekazywanie zmiennej pomiędzy klasami  (Przeczytany 5868 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.