尝试为类内的私有结构编写setter函数。还没有找到允许访问结构的声明方法。使用类成员函数访问类内的私有结构
该结构可能不能移出课程。该函数必须是该类的成员。前向声明可能不被使用。
class Editor
{
public:
void setName (string s);
private:
struct Object
{
string name;
}Instance;
}Ed;
void Editor::setName (string s)
{
name = s; // no access
}
==================================
class Editor
{
public:
friend void setName (Editor &m , string s);
private:
struct Object
{
int name;
}Instance;
}Ed;
void setName (Editor &m , string s)
{
name = s; // no access
}
== ================================
class Editor
{
public:
friend void setName (Object &m , string s); //invalid declaration ( Object is undefined)
private:
struct Object
{
string name;
}Instance;
}Ed;
请张贴实际的代码。 – juanchopanza