在同一范围C+&#x2B上未申报的凹痕器
播放C ++ 20
模块,我有以下片段:
export {
template<class T>
class Suite {
private:
std::vector<ConcreteBuilder<T>> things {};
};
template <class T>
class ConcreteBuilder : Builder<T> {
private:
// A collection of things of function pointers or functors
std::vector<std::function<void()>> things;
public:
// Virtual destructor
virtual ~TestBuilder() override {};
// Add a new thing to the collection of things
template<typename Function>
void add(Function&& fn) {
tests.push_back(std::forward<Function>(fn));
}
// override the build() base method from Builder<T>
virtual T build() const override {
return this->things;
}
};
}
而且我将获得此clang
错误:
error: use of undeclared identifier 'ConcreteBuilder'
std::vector<ConcreteBuilder> things {};
为什么我无法访问在同一模块中的类型相同的水平?
Playing with C++ 20
modules, I have the following snippet:
export {
template<class T>
class Suite {
private:
std::vector<ConcreteBuilder<T>> things {};
};
template <class T>
class ConcreteBuilder : Builder<T> {
private:
// A collection of things of function pointers or functors
std::vector<std::function<void()>> things;
public:
// Virtual destructor
virtual ~TestBuilder() override {};
// Add a new thing to the collection of things
template<typename Function>
void add(Function&& fn) {
tests.push_back(std::forward<Function>(fn));
}
// override the build() base method from Builder<T>
virtual T build() const override {
return this->things;
}
};
}
And I am getting this Clang
error:
error: use of undeclared identifier 'ConcreteBuilder'
std::vector<ConcreteBuilder> things {};
Why I can't access to a type that are in the same module at the same level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器从上到下来编译文件,而不是一次全部。它正在按照
std :: vector&lt; concretebuilder&lt; t&gt;&gt;
的定义进行定义,然后才能获得类ConcreteBuilder
的定义。因此,您需要在定义
ConcreteBuilder
的定义之后移动suite
的定义,因此编译器知道在向量定义中使用它时它是什么。The compiler compiles the file from the top down, not all at once. It is hitting the definition of
std::vector<ConcreteBuilder<T>>
before it gets to the definition ofclass ConcreteBuilder
.So, you need to move your definition of
Suite
after the definition ofConcreteBuilder
, so the compiler knows what it is when you use it in the vector definition.