构造函数在这里:
当我声明我的setLeft()
函数时,它告诉我m_pLeft
未定义。我已经尝试过把它移到那个地方,并且不能说它不是未定义的。
SetLeft定义为 void setLeft(BookRecord * leftpointer){ * m_pLeft = * leftpointer; }
#pragma once
class BookRecord
{
private:
char m_sName[100]; //unique names for each book
long m_lStockNum; //a stock number, similar to a barcode
int m_iClassification; //how a book should be classified, similar to a dewey decimal system
double m_dCost; //The price of the book
int m_iCount; //How many books are in stock
BookRecord *m_pLeft; //Left pointer for the tree
BookRecord *m_pRight; //right Pointer from the tree
public:
BookRecord(void);
BookRecord(char *name,long sn, int cl,double cost);
~BookRecord();
void getName(char *name);
void setName(char *Sname);
long getStockNum();
void setStockNum(long sn);
void getClassification(int& cl);
void setClassification(int cl);
double getCost();
void setCost(double c);
int getNumberInStock();
void setNumberInStock(int count);
void printRecord();
BookRecord getLeft();
BookRecord getRight();
void setLeft(BookRecord *leftpointer);
void setRight(BookRecord *rightpointer);
};
答案 0 :(得分:3)
当我声明我的
setLeft()
函数时,它告诉我m_pLeft
未定义。
您看到的错误不是来自setLeft()
成员函数的声明,而是来自其定义(声明未引用{{1 }}):
m_pLeft
像这样的定义的问题是编译器将其视为独立函数,因此// This is incorrect - it will not compile
void setLeft(BookRecord *leftpointer) {
m_pLeft = leftpointer;
}
成员不在范围内。您需要告诉编译器您正在定义成员函数,如下所示:
m_pLeft