//Items.hПроблемы с отправкой переменных данных к другим классам
class Items
{
public:
Items();
Items(string, string, double, int, int);
//Item setters
void setDesciption(string);
void setSku(int);
void setLocation(int);
void setSupplier(string);
void setCost(double);
//Item getters
string getDescription();
int getSku();
int getLocation();
string getSupplier();
double getCost();
private:
//Item variables
string _description;
string _supplier;
double _cost;
int _sku;
int _location;
};
// Конструктор в классе предметов
Items::Items(string description, string supplier, double cost, int sku, int location)
{
setDesciption(description);
setSupplier(supplier);
setCost(cost);
setSku(sku);
setLocation(location);
}
// Это надстройка элементы класса // Эта функция предназначенный для установки значений для переменных в классе элементов путем передачи их через свой конструктор по умолчанию. // Теперь я тестировал вызов функции AddOrDeleteItems в main(), и он отлично работает, но когда я пытаюсь использовать его в другом файле класса (как и класс add items), переменные в файле items.h никогда не устанавливайте и не возвращайте значения по умолчанию.
void AddOrDeleteItems::newItem()
{
string description;
string supplier;
double cost;
int sku;
int location;
//Run checks on things like sku length, location.
cout << "Add a new product please enter the following.\n\n";
cout << "Description: ";
getline(cin, description);
cout << "\nSupplier: ";
getline(cin, supplier);
cout << "\nCost: ";
cin >> cost;
cout << "\nSku: ";
cin >> sku;
cout << "\nLocation: ";
cin >> location;
Items ItemsObj(description, supplier, cost, sku, location);
}
Edit добавить свои методы получения и установки, если это помогает ... (Также исправлен орфографическую ошибку в моих сеттеров и остальную часть кода ... лол)
//Item Setters
void Items::setDescription(string x)
{
_description = x;
}
void Items::setSku(int x)
{
_sku = x;
}
void Items::setLocation(int x)
{
_location = x;
}
void Items::setSupplier(string x)
{
_supplier = x;
}
void Items::setCost(double x)
{
_cost = x;
}
//Item Getters
string Items::getDescription()
{
return _description;
}
int Items::getSku()
{
return _sku;
}
int Items::getLocation()
{
return _location;
}
string Items::getSupplier()
{
return _supplier;
}
double Items::getCost()
{
return _cost;
}
lolz @ 'комплектDesciption'. – Downvoter
Hahahaha cheers = P плохо исправить это, но я не думаю, что это вызывает проблему. –
@MaxMcgregor Я не уверен, как вы ожидаете, что переменные будут установлены с помощью метода 'newItem'. Он не возвращает созданный элемент и не принимает его в качестве параметра и модифицирует его. Он делает это: создание нового объекта 'Items', который сразу же уничтожается при возврате из функции. Что вы хотите, чтобы этот метод выполнял именно? –