我的全文太长了,但这里是一席之地,将反映我的问题的本质:
class BPCFGParser {
public:
...
...
class Edge {
...
...
};
class ActiveEquivClass {
...
...
};
class PassiveEquivClass {
...
...
};
struct EqActiveEquivClass {
...
...
};
struct EqPassiveEquivClass {
...
...
};
unordered_map<ActiveEquivClass, Edge *, hash<ActiveEquivClass>, EqActiveEquivClass> discovered_active_edges;
unordered_map<PassiveEquivClass, Edge *, hash<PassiveEquivClass>, EqPassiveEquivClass> discovered_passive_edges;
};
namespace std {
template <>
class hash<BPCFGParser::ActiveEquivClass>
{
public:
size_t operator()(const BPCFGParser::ActiveEquivClass & aec) const {
}
};
template <>
class hash<BPCFGParser::PassiveEquivClass>
{
public:
size_t operator()(const BPCFGParser::PassiveEquivClass & pec) const {
}
};
}
在我编纂这一法典时,我有以下错误:
In file included from BPCFGParser.cpp:3,
from experiments.cpp:2:
BPCFGParser.h:408: error: specialization of ‘std::hash<BPCFGParser::ActiveEquivClass>’ after instantiation
BPCFGParser.h:408: error: redefinition of ‘class std::hash<BPCFGParser::ActiveEquivClass>’
/usr/include/c++/4.3/tr1_impl/functional_hash.h:44: error: previous definition of ‘class std::hash<BPCFGParser::ActiveEquivClass>’
BPCFGParser.h:445: error: specialization of ‘std::hash<BPCFGParser::PassiveEquivClass>’ after instantiation
BPCFGParser.h:445: error: redefinition of ‘class std::hash<BPCFGParser::PassiveEquivClass>’
/usr/include/c++/4.3/tr1_impl/functional_hash.h:44: error: previous definition of ‘class std::hash<BPCFGParser::PassiveEquivClass>’
现在,我必须专门研究:这些班级的教益(因为标准:现金定义不包括用户界定的类型)。 当我把这些模板专业提升到类别(BPCFGParser
)的定义之前,我就在所尝试的不同事情以及某些地方( 我读到:
Whenever you use a class as a template parameter, the declaration of that class must be complete and not simply forward declared.
因此,我 m。 在<条码>、CFGParser下定义之后,我不能在“条码”栏目“BPCFGParser<>条码”定义之前对模板进行专门化,我怎么做?
你们需要将专业提升到博帕尔多斯大学内部的一个内部班级。 这样做符合这两项要求。
非常感谢:
<代码>hash 类别在std
上界定。 这使我无法在非名称空间范围内专门使用<代码>hash的模板。 甚至:
template <>
class std::hash<ActiveEquivClass> {
...
没有工作。 但是,当我附上<代码>的称呼空间({})时,它给我们留下了错误:
In file included from BPCFGParser.cpp:3,
from experiments.cpp:2:
BPCFGParser.h:225: error: expected unqualified-id before ‘namespace’
experiments.cpp:7: error: expected `} at end of input
BPCFGParser.h:222: error: expected unqualified-id at end of input
在pacreviews的回答中,有人声称名称空间无法在班级内界定。 因此,我仍然 st。