Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 函数继承的问题_C++_Class_Inheritance_Header_Parameter Passing - Fatal编程技术网

C++ 函数继承的问题

C++ 函数继承的问题,c++,class,inheritance,header,parameter-passing,C++,Class,Inheritance,Header,Parameter Passing,我有3个文件,2个头文件和一个.CPP文件 头文件代码 STX.H 我正在尝试从Employee.CPP文件向其传递姓氏变量 void SeqList::Delete(const DataType& item) { lastname = item; } .CPP中的错误是lastname未定义 这是employee的头文件的外观 class Employee { private: string lastname; public: void SeqList::D

我有3个文件,2个头文件和一个.CPP文件

头文件代码 STX.H

我正在尝试从Employee.CPP文件向其传递姓氏变量

void SeqList::Delete(const DataType& item)
{
    lastname = item;
}
.CPP中的错误是lastname未定义

这是employee的头文件的外观

class Employee
{
private:
    string lastname;

public:
    void SeqList::Delete(const DataType& item);
此类中的错误为“限定符必须是“Employee”的基类”

我该如何解决这个问题


我仍在努力准确地掌握如何继承东西,请耐心等待。

首先,在您的类
Employee
中,
lasname
private
:只有Employee的成员函数才能访问它

然后,您的类定义中的限定符
SeqList::
出现语法问题:

class Employee
{
...
public:
    void SeqList::Delete(const DataType& item);   //oops !! 
...
};
如果
Delete()
Employee
的memeber函数,只需删除限定符即可


如果
Delete()
不是
Employee
的成员,但应该是另一个类的成员(即
SeqList
),那么您在错误的位置定义了您的函数。您必须在SeqList类中声明它。但是在这种情况下,
lastname
:SeqList成员函数将无法访问它,除非您将其公开。

如果
Delete
函数不是
Employee
类的e成员,您为什么要这样做你可以在
Employee
类中声明它吗?以及
lastname
声明的位置(如果在任何地方)?你可以创建一个并展示给我们吗?我认为应该这样做,我认为这已经足够少了。
class Employee
{
...
public:
    void SeqList::Delete(const DataType& item);   //oops !! 
...
};