2015-12-09 27 views
0

我收到的错误是C3867 'Member::getMN': non-standard syntax; use '&' to create a pointer to member'。同样的错误为getID,nBks,成本和tcost。C++创建书店,语法错误

询问客户的姓名和身份证号码,然后查询他们想要的书籍数量并索要该书的费用。必须显示所有信息。不知道我的错误究竟在哪里。

#ifndef MEMBER_H 
#define MEMBER_H 
#include <string> 
#include <iostream> 

using namespace std; 

// define the class members and member function prototypes here 
class Member 
{ 
private: 
    string MemberName;//customer name 
    string MemberID;//customer id 
    int numBooks=0;//number of books 
    double PurchaseAmt=0;//cost of books 

public: 
    void setMN(string); 
    void setmID(string); 
    void setnBks(int); 
    void setcost(double); 
    string getMN() const; 
    string getID()const; 
    int nBks()const; 
    double cost()const;//cost of a book 
    double tcost()const; 
}; 
#endif 

#include "member.h" // Needed for the member class 
#include <iostream>  // Needed for cout 
#include <cstdlib>  // Needed for the exit function 
using namespace std; 

void Member::setMN(string name)//string size for membername 
{ if (name.size() < 12) 
     MemberName = name.substr(0, 12); 
    else 
    { 
     cout << "Invalid Member ID\n"; 
     system("pause"); 
     exit(EXIT_FAILURE); 
    } 
} 

void Member::setmID(string ID)//string size for MemberID 
{ if (ID.size() < 5) 
     MemberID = ID.substr(0,5); 
    else 
    { 
     cout << "Invalid Member ID\n"; 
     system("pause"); 
     exit(EXIT_FAILURE); 
    } 

} 
void Member::setnBks(int num)//check for number of books 
{ if (num > 0) 
     numBooks = num; 
    else 
    { 
     cout << "Invalid book count, must be over 0.\n"; 
     system("pause"); 
     exit(EXIT_FAILURE); 
    } 
} 

void Member::setcost(double amount)//check for cost of the book. 
{ if (amount > 0) 
     PurchaseAmt = amount; 
    else 
    { 
     cout << "Invalid cost, can not be less then 0.\n"; 
     system("pause"); 
     exit(EXIT_FAILURE); 
    } 
} 


string Member::getMN() const 
{ return MemberName; 
} 

string Member::getID() const 
{ return MemberID; 
} 

int Member::nBks() const 
{ return numBooks; 
} 

double Member::cost() const 
{ return PurchaseAmt; 
} 

double Member::tcost() const//getting the total cost of the book(s) 
{ return numBooks * numBooks; 

} 

#include <iostream> 
#include <string> 
#include <iomanip> 
#include "member.h" // Needed for Member class 

using namespace std; 

void getinfo(Member&); 
void display(Member); 

int main() 
{ 
    Member books; 

    system("pause"); 
    return 0; 
} // end main 

//this function returns member name and id, also number of books and the cost. 
    // this function displays the book store's data. 
void getinfo(Member& x) 
{ 
    string MemberName, MemberID; 
    int numBooks; 
    double PurchaseAmt; 

    cout << fixed << showpoint << setprecision(2); 

    cout << "What is the members last name, must be under 12 char?\n"; 
    cin >> MemberName; 
    x.setMN(MemberName); 

    cout << "What is the members ID, must be under 5 int?\n"; 
    cin >> MemberID; 
    x.setmID(MemberID); 

    cout << "How many books?\n"; 
    cin >> numBooks; 
    x.setnBks(numBooks); 

    cout << "How much does each book cost?\n"; 
    cin >> PurchaseAmt; 
    x.setcost(PurchaseAmt); 

} // end getting information. 

void display(Member x) 
{ 
    cout << fixed << showpoint << setprecision(2); 
    cout << "The member's last name is : " << x.getMN << endl; 
    cout << "The member's ID is : " << x.getID << endl; 
    cout << "The number of books bought are : " << x.nBks << endl; 
    cout << "The cost per book is : " << x.cost << endl; 
    cout << "The total is : " << x.tcost << endl; 

} 
+1

在发布有关错误的问题,尽量减少代码只是相关部分(最好是建立一个[最小,完整,可验证示例](http://stackoverflow.com/help/mcve)向我们展示),并在您显示的源代码中标出错误行(例如代码中的注释)。编译器会告诉你*确切地说*它发现错误的地方,它会一直显示文件名和行号,有时甚至会显示函数名。 –

+0

会做,我很抱歉大量的代码。 – kobe

回答

1

你刚才忘了()方法名称后

void display(Member x) 
{ 
    cout << fixed << showpoint << setprecision(2); 
    cout << "The member's last name is : " << x.getMN() << endl; 
    cout << "The member's ID is : " << x.getID() << endl; 
    cout << "The number of books bought are : " << x.nBks() << endl; 
    cout << "The cost per book is : " << x.cost() << endl; 
    cout << "The total is : " << x.tcost() << endl; 

} 
+0

哦哇..我不相信我错过了..非常感谢你 – kobe