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.
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. 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):
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
.
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.