成员函数设成友元函数还是不能访问私有成员
看上去一堆乱七八糟的东西 其实就是一个简单的问题 prune是plate类的成员函数 要用node类的私有数据,所以在node类中将prune函数声明为友元 然后些prune函数的实现语句 发现任然没法访问所需要的node类的私有数据,求大神相助!
################
类定义
################
#include<vector>
#include<string>
#include<fstream>
#include<iostream>
#include<map>
#include<stdlib.h>//包含atof函数
#include<sstream>//为了转换double到string
//---------------------------------------------------------------
typedef std::vector<std::vector<std::string>> Raw_format;
//---------------------------------------------------------------
//定义node类
//---------------------------------------------------------------
class plate;
class Node
{
public:
typedef std::vector<std::vector<double>> Node_format;
void get_and_set(Raw_format&);
void display();
Node_format extract();
friend void Plate::prune(Node&);
private:
Node_format original,modified;
};
//-----------------------------------------------------------------
//定义plate类(element的一种)
//-----------------------------------------------------------------
class Plate
{
public:
typedef std::vector<std::vector<double>> Plate_format;
typedef std::map<int,std::vector<double>> Plate_set_format;
void get_and_set(Element::Element_format&);
void display();
Plate_set_format get_the_set();
Plate_format extract();
void prune(Node&);
private:
Plate_format original,modified;
};
################################
类实现(一部分)
################################
void Plate::prune(Node &n)
{
n.original//示意一下,这里我的编译器就提示有问题了,说不可访问
}
#include <iostream>
using namespace std;
#include<vector>
#include<string>
#include<fstream>
#include<iostream>
#include<map>
#include<stdlib.h>//
#include<sstream>//
//---------------------------------------------------------------
typedef std::vector<std::vector<std::string> > Raw_format;
//---------------------------------------------------------------
//---------------------------------------------------------------
class plate;
class Node;
class Plate
{
public:
typedef std::vector<std::vector<double> > Plate_format;
typedef std::map<int,std::vector<double> > Plate_set_format;
// void get_and_set(Element::Element_format&);
// void display();
// Plate_set_format get_the_set();
// Plate_format extract();
void prune(Node&);
private:
Plate_format original,modified;
};
class Node
{
public:
typedef std::vector<std::vector<double> > Node_format;
// void get_and_set(Raw_format&);
// void display();
// Node_format extract();
friend void Plate::prune(Node&);
private:
Node_format original,modified;
};
void Plate::prune(Node &n)
{
n.original.empty();//
}
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
friend void Plate::prune(Node &n);
friend class Plate;