I have a code:
#include "stdafx.h"
#include "memory"
#include <gtest\gtest.h>
class Money
{
public:
explicit Money(int value) :value(value) {} ;
Money(Money&& m) :value(m.returnValue()) {};
Money(const Money &m) = default;
Money operator-(const Money &m) ;
Money &operator=(Money &&m) { return Money(m.returnValue()); };
Money &operator=(const Money &m)=default;
int returnValue() const { return value; };
~Money() = default;
private:
int value;
};
Money Money::operator-(const Money &m)
{
return Money(value - m.returnValue());
}
class Bank {
public:
Bank(Money m) :propertiesBank(std::make_unique<PropertiesBank>(std::move(m))) {};
int returnMoney() const { return propertiesBank->money->returnValue(); }
~Bank() = default;
private:
struct PropertiesBank;
std::unique_ptr<PropertiesBank> propertiesBank;
};
struct Bank::PropertiesBank
{
std::shared_ptr<Money> money;
PropertiesBank(Money&& m) :money(std::make_shared<Money>(m)) {};
};
int main()
{
Money k(1000);
Bank bank(k);
return 0;
}
I want display(returnMoney()) money in the Bank, but I can't. I could make class with struct Impl and unique_ptr for training. I know, that unique can't copy. How can I make this programm? Are the rest of my code is well?
Error
Error C2027 use of undefined type 'Bank::PropertiesBank' Error
C2039 'returnValue': is not a member of 'std::unique_ptr>'