Wiem, że większość jest źle, zacząłem jakoś kombinować ze wskaźnikami z referencją bez ale coś mi nie poszło.
main.cpp
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include "Karton.h"
#include <string>
int main()
{
Karton t1(50, 2);
t1.WlozWyjmij(20);
t1.Waga();
int outt;
std::cin >> outt;
return 0;
}
Karton.h
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
class Karton
{
public:
Karton(int m_dop, int m_ile);
int WlozWyjmij(int wlozwyj);
void Waga();
private:
int dop; // reprezentuje dopuszczalny ciezar umieszczony w kartonie
int ile; // reprezentuje ciezar umieszczony w kartonie
};
Karton.cpp
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include "Karton.h"
#include <string>
Karton::Karton(int m_dop=5, int m_ile=0)
{
dop = m_dop; // reprezentuje dopuszczalny ciezar umieszczony w kartonie
ile = m_ile; // reprezentuje ciezar umieszczony w kartonie
}
int Karton::WlozWyjmij(int wlozwyj)
{
int *wsk =& ile;
if (wlozwyj > (dop - wsk))
{
return false;
}
else
{
return wsk+wlozwyj;
std::cout <<wsk<< std::endl;
}
}
void Karton::Waga()
{
std::cout << ile << std::endl;
}