compiler-Fehlermeldung: privat ist in diesem Zusammenhang

Bin ich, eine Klasse zu schreiben, und wenn ich kompiliere, bekomme ich eine Fehlermeldung, die sagt, "privat ist in diesem Kontext" und ein anderer, der sagt, "ungültige Verwendung der nicht-statischen Daten-member". Aber wenn ich kommentiere alles, was vor der addShipment Funktion in meiner cpp-Datei, kompiliert er problemlos. Kann mir jemand bitte erklären, was anders ist, dass es manchmal zu einem Fehler, und manchmal nicht, und wenn die zwei verschiedenen Arten von Fehlern beziehen.

Produkt.h:

#ifndef PRODUCT_H
#define PRODUCT_H

#include <iostream>

class Product {
    public:
        Product(int productID, std::string productName);
        std::string getDescription();
        void setDescription(std::string description);
        std::string getName();
        int getID();
        int getNumberSold();
        double getTotalPaid();
        int getInventoryCount();
        void addShipment(int shipmentQuantity, double shipmentCost);
        void reduceInventory(int purchaseQuantity);
        double getPrice();
    private:
        int productID;
        std::string name;
        std::string description;
        double totalPaid;
        int inventoryCount;
        int numSold;
};

#endif

Product.cpp:

#include <iostream>
#include "Product.h"
using namespace std;

Product::Product(int productID, string productName) {
    Product::productID = productID;
    Product::name = productName;
}

string Product::getDescription() {
    return Product::description;
}

void Product::setDescription(string description) {
    Product::description = description;
}

string Product::getName() {
    return Product::name;
}

int Product::getID() {
    return Product::productID;
}

int Product::getNumberSold() {
    return Product::numSold;
}

double Product::getTotalPaid() {
    if(Product::totalPaid < 1) {
        totalPaid = 0;
    }
    return Product::totalPaid;
}

int Product::getInventoryCount() {
    Product::inventoryCount = 0; 
    return Product::inventoryCount;
}

void addShipment(int shipmentQuantity, double shipmentCost) {
    Product::inventoryCount = Product::inventoryCount + shipmentQuantity;
    Product::totalPaid = Product::totalPaid + shipmentCost;
}

void reduceInventory(int purchaseQuantity) {
    Product::inventoryCount = Product::inventoryCount - purchaseQuantity;
    Product::numSold = Product::numSold + purchaseQuantity;
}

double getPrice() {
    int price = (Product::totalPaid / static_cast<double>(Product::inventoryCount + Product::numSold)) * 1.25;
    return price;
}
Unentgeltliche Aufnahme von <iostream>, noch nicht enthalten für <string> ?

InformationsquelleAutor AdamK | 2017-04-01

Schreibe einen Kommentar