이상한 문제가 발생했습니다.오류 C2248 : 클래스에서 선언 된 전용 멤버에 액세스 할 수 없습니다. 컴파일러 이상한 동작
#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;
};
구현이 매우 간단하고 주장이 컴파일되지 않는 몇 가지 이유에 대해 : 나는 다음과 같은 클래스가
error C2248: 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream' : cannot access private member declared in class 'std::basic_ifstream<_Elem,_Traits>'
그리고 그것은 마지막 줄에 저를 참조한다. 첫째, 멤버는 비공개가 아니며 멤버는 실제로 특정 추상 클래스에서 비공개입니다. 나는 그 문제를 발견 할 수 없다.
RuleProvider::RuleProvider(string path) : _path(path)
{
this->_file.open(path);
}
다른 기능 만 ifstream
년대 같은 is_open
등등과 같은 기본 기능을 사용 여기
RuleProvider
을 초기화하고이를 (다형 포인터로) 벡터로 푸시하는 객체를 초기에 사용합니다. 이 객체의 생성자의 코드입니다 : 여기
(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());
}
}
함수 선언의 모든이 (내가 결코 기능 '정의의 하나에 단어 RuleProvider
을 언급하지 그래서 나는 그것이 불필요 가정) :
class GlobalRuleProvider : public RuleProvider
{
public:
GlobalRuleProvider(string);
virtual Rule readNext();
~GlobalRuleProvider(void);
};
또 다른 2 클래스의 경우 정확하게 다른 이름 (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;
};
여기에 누구의 생성자 일반 객체가 위입니다입니다 :
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;
};
은 어디에서 문제가 될 수 있을까? 어떤 이유로 든
RuleProvider
의 생성자를 의심합니다.
오류를 재현하는 최소한의 프로그램을 제공하십시오. 이 코드로는 충분하지 않습니다. – 0x499602D2
밑줄이있는 멤버의 이름을 시작하면 안됩니다. 이는 컴파일러 빌더를 위해 예약되어 있습니다. – wimh
@Wimmel 당신은 무엇을 의미합니까? 국제 대회가 아닌가? 나는 항상 그것을 사용한다. – Joseph