2017-02-22 11 views
-2

Ich bin neu in C++ und ich versuche derzeit, ein Programm zu schreiben, das Main verwendet, um Funktionen aufzurufen, die separat geschrieben werden, und ich habe versucht, die Definitionen für die Header-Datei-Deklarationen zu schreiben, und ich bekomme Fehler mit einige Funktionen, die ichkeine passende Funktion für Anruf

Store.hpp

#ifndef STORE_HPP 

#define STORE_HPP 
class Product; 
class Customer; 
#include<string> 

#include "Customer.hpp" 
#include "Product.hpp" 
class Store 

{ 

private: 

std::vector<Product*> inventory; 

std::vector<Customer*> members; 


public: 

void addProduct(Product* p); 

void addMember(Customer* c); 

Product* getProductFromID(std::string); 

Customer* getMemberFromID(std::string); 

void productSearch(std::string str); 

void addProductToMemberCart(std::string pID, std::string mID); 

void checkOutMember(std::string mID); 

}; 

#endif 

i Probleme im Code markiert haben das Schreiben für diese Funktion den Code habe mir helfen

store.cpp

#include <iostream> 
#include <string.h> 
#include "Customer.hpp" 
#include "Store.hpp" 
#include "Product.hpp" 
using namespace std; 

string id; 

void Store::addProduct(Product* p)  //error 1 no matching function 
{ 

    Product* p(std::string id, std::string t, std::string d, double p, int qa); 
    inventory.push_back(p); 
} 

void Store:: addMember(Customer* c) 
{ 
    members.push_back(c->getAccountID()); 
} 

Product* Store::getProductFromID(std::string id) 
{ 
    for(int i = 0; i < inventory.size(); i++) 
    { 
     Product* p=inventory.at(i); 
     if(p->getIdCode()= id) 
     { 
      return p; 
     } 
} 
    return NULL; 
} 
Customer* Store:: getMemberFromID(std::string id) 
{ 
    for(int i = 0; i < members.size(); i++) 
    { 
     Customer* c = members.at(i); 
     if(c->getAccountID() == id) 
     { 

      return c; 
     } 
    } 
    return NULL; 
} 
void std::Store productSearch(std::string str) 
{ 
    for(int i = 0; i < inventory.size(); i++) 
    { 
     if(inventory[i] == str) 
     { 
      Product stud(inventory[i],inventory[i+1],inventory[i+2],inventory[i+3],inventory[i+4]); 
cout<<getIdCode(); 

cout<<getTitle(); 

cout<<getDescription(); 

cout<<getPrice(); 

cout<<getQuantityAvailable(); 
     } 
    } 
} 
void addProductToMemberCart(std::string pID, std::string mID) 
{ 
    cout<<"adding to cart"<<endl; 
    getMemberFromID(mID)->addProductToCart(pID); 

} 

void checkOutMember(std::string mID) 
{ 
    Customer* c=getAccountID(mID) 
    mID=getMemberFromID(std::string mID); 
    if(mID=="NULL") 
    { 
     cout<<mID<<"is not found"<<endl; 
    } 

} 

customer.hpp

#ifndef CUSTOMER_HPP 

#define CUSTOMER_HPP 

#include<vector> 

#include "Product.hpp" 

class Customer 

{ 

private: 

std::vector<std::string> cart; 

std::string name; 

std::string accountID; 

bool premiumMember; 

public: 

Customer(std::string n, std::string a, bool pm); 

std::string getAccountID(); 

//std::vector getCart(); 

void addProductToCart(std::string); 

bool isPremiumMember(); 

void emptyCart(); 

}; 

#endif 

product.hpp

#ifndef PRODUCT_HPP 

#define PRODUCT_HPP 

#include<vector> 

class Product 

{ 

private: 

std::string idCode; 

std::string title; 

std::string description; 

double price; 

int quantityAvailable; 

public: 

Product(std::string id, std::string t, std::string d, double p, int qa); 

std::string getIdCode(); 

std::string getTitle(); 

std::string getDescription(); 

double getPrice(); 

int getQuantityAvailable(); 

void decreaseQuantity(); 

}; 

#endif 
+3

Bitte senden Sie uns eine [MCVE]. –

+0

Vittorio ich versuche, ein Produkt in die vectory Inventar und die Funktion addProduct in der store.hpp hinzufügen, und ich habe Probleme, wie Sie den Code für diese Funktion, die in store.cpp ist schreiben Sie können nur auf i habe den Fehler da drüben – user1210000

+0

kommentiert Sie müssen Ihr Beispiel minimieren - Sie haben buchstäblich Ihren gesamten Code gepostet. Machen Sie ein minimales Beispiel, das das Problem reproduziert und stattdessen veröffentlicht. –

Antwort

1

Sie Code viele Warnungen und Fehler als Stände gibt. Wenn Sie sich in dieser Situation befinden und nicht herausfinden können, was einer von ihnen bedeutet, versuchen Sie, einige der anderen zu beheben.

Ihr Hauptproblem ist in addProduct, aber es gibt andere

using namespace std; 

string id; //<---- what's this for? 

void Store::addProduct(Product* p)  //error 1 no matching function 
{ 

    //Product* p(std::string id, std::string t, std::string d, double p, int qa); 
    //<--- This line had the error and isn't needed 
    inventory.push_back(p); 
} 

void Store::addMember(Customer* c) 
{ 
// members.push_back(c->getAccountID()); //<--- this errors too 
    members.push_back(c); 
} 

Product* Store::getProductFromID(std::string id) 
{ 
    for (size_t i = 0; i < inventory.size(); i++) 
    { 
     Product* p = inventory.at(i); 
     //if (p->getIdCode() = id) //<-- be careful with = and == 
     if (p->getIdCode() == id) //<--- 
     { 
      return p; 
     } 
    } 
    return NULL; 
} 

Customer* Store::getMemberFromID(std::string id) 
{ 
    for (size_t i = 0; i < members.size(); i++) 
    { 
     Customer* c = members.at(i); 
     if (c->getAccountID() == id) 
     { 
      return c; 
     } 
    } 
    return NULL; 
} 

//void std::Store productSearch(std::string str) 
void Store::productSearch(std::string str) // <---- note this change too 
{ 
    for (size_t i = 0; i < inventory.size(); i++) 
    { 
     //if (inventory[i] == str) //<<--------! 
     if (inventory[i]->getDescription() == str) 
     { 
      //Product stud(inventory[i], inventory[i + 1], inventory[i + 2], inventory[i + 3], inventory[i + 4]); 
      // This is five Products from the inventory, not the i-th product in your invetory 
      Product stud(*inventory[i]);//<---- I assume     
      cout << stud.getIdCode(); 
      cout << stud.getTitle(); 
      cout << stud.getDescription(); 
      cout << stud.getPrice(); 
      cout << stud.getQuantityAvailable(); 
     } 
    } 
} 

void Store::addProductToMemberCart(std::string pID, std::string mID)//<--- note note std::Store addProductToMemberCart 
{ 
    cout << "adding to cart" << endl; 
    getMemberFromID(mID)->addProductToCart(pID); 

} 

void Store::checkOutMember(std::string mID)//<--- 
{ 
    //Customer* c = getAccountID(mID);//<<---? 
     //mID = getMemberFromID(std::string mID); //<---? 
    Customer* c = getMemberFromID(mID); //Just this? 
    if (c == NULL)//<---rather than "NULL" but nullptr might be better 
    {    // or not using pointers at all 
     cout << mID << "is not found" << endl; 
    } 

} 
+0

thankyou so viel @doctorlove du hast mir wirklich geholfen, immer noch einige Fragen und Fehler – user1210000

+0

, wie man für checkboxmember schreiben habe immer noch Probleme mit checkboxmember Vielen Dank im Voraus Kunde * c = Store :: getMemberFromID (mID); Ich habe dies innerhalb der Checkbox geändert – user1210000

+0

habe es thanqq wieder – user1210000

Verwandte Themen