[英]Error C2248: cannot access private member declared in class, compiler weird behavior
I'm experiencing a weird problem. 我遇到一个奇怪的问题。 I have the following class:
我有以下课程:
#pragma once
#include <fstream>
#include "Rule.h"
#include <string>
#include <iostream>
using namespace std;
class RuleProvider
{
public:
RuleProvider(string);
bool isValid();
string getError();
bool isEOF();
virtual Rule readNext() = 0;
void set();
protected:
string _error;
string _path;
ifstream _file;
};
Implementation is very simple and for some reason it does not compile, claiming: 实现非常简单,由于某种原因它无法编译,并声称:
error C2248: 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream' : cannot access private member declared in class 'std::basic_ifstream<_Elem,_Traits>'
And it is referencing me to the last line. 它使我引用了最后一行。 First, the member isn't even private, no members are actually private in this specific abstract class.
首先,成员甚至不是私有的,在这个特定的抽象类中,没有成员实际上是私有的。 I just can't spot the problem.
我只是无法发现问题。
Here is the implementation of the constructor: 这是构造函数的实现:
RuleProvider::RuleProvider(string path) : _path(path)
{
this->_file.open(path);
}
The other functions only use ifstream
's built-in functions such as is_open
and so. 其他函数仅使用
ifstream
的内置函数,例如is_open
等。 In the main program I initial an object that through his constructor is initializing many derived classes of RuleProvider
and pushing them (as polymorphic pointers) into a vector. 在主程序中,我初始化了一个对象,该对象通过他的构造函数正在初始化
RuleProvider
许多派生类,并将它们(作为多态指针)推送到向量中。 This is the code snippet in the constructor of that object: 这是该对象的构造函数中的代码片段:
(this->_providers).push_back(&this->_globalProvider);
for(int i = 0 ; i < orgProviderSize ; i++)
{
(this->_providers).push_back(new OrgRuleProvider(orgProviderPath[i]));
}
for(int i = 0 ; i < userProviderSize ; i++)
{
(this->_providers).push_back(new UserRuleProvider(userProviderPath[i]));
}
for(int i = 0 ; i < orgProviderSize + userProviderSize + 1 ; i++)
{
while(!((this->_providers)[i]->isEOF()))
{
this->_rules.insert((this->_providers)[i]->readNext());
}
}
Here are all of the functions declarations (I never mention the word RuleProvider
in any of the functions' definition so I assume it's unnecessary): 这是所有函数的声明(我在任何函数的定义中都从未提到过
RuleProvider
一词,因此我认为这是不必要的):
class GlobalRuleProvider : public RuleProvider
{
public:
GlobalRuleProvider(string);
virtual Rule readNext();
~GlobalRuleProvider(void);
};
And same exactly for another 2 classes, just using another name (and a different implementation of readNext()
) - OrgRuleProvider
and UserRuleProvider
. 对于另外两个类,完全相同,只是使用另一个名称(以及
readNext()
的不同实现) OrgRuleProvider
和UserRuleProvider
。
class Rule
{
public:
Rule(string, string, string, string, string);
string getSrcIP() const;
string getDstIP() const;
string getSrcPort() const;
string getDstPort() const;
string getProtocol() const;
bool operator==(const Rule& other) const;
bool operator<(const Rule& other) const;
bool operator>(const Rule& other) const;
private:
static bool isValidIP(string);
static bool isValidPort(string);
static bool isValidProtocol(string);
string _srcIP;
string _srcPort;
string _dstIP;
string _dstPort;
string _protocol;
};
and here's the general object whose constructor is the above: 这是上面构造函数的常规对象:
class PacketFilter
{
public:
PacketFilter(string, string*, int, string*, int);
bool filter(string srcIP, string srcPort, string dstIP, string dstPort, string protocol);
~PacketFilter(void);
private:
void update();
GlobalRuleProvider _globalProvider;
vector<RuleProvider*> _providers;
set<Rule> _rules;
};
Where could the problem be? 问题可能在哪里? I suspect the basic
RuleProvider
's constructor for some reason. 我出于某种原因怀疑基本
RuleProvider
的构造函数。
Problem is this ifstream _file;
问题是这个
ifstream _file;
. 。 Streams are not copyable.
流不可复制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.