在同一范围C+&#x2B上未申报的凹痕器

发布于 2025-02-06 07:03:41 字数 1153 浏览 2 评论 0原文

播放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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑红尘 2025-02-13 07:03:41

编译器从上到下来编译文件,而不是一次全部。它正在按照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 of class ConcreteBuilder.

So, you need to move your definition of Suite after the definition of ConcreteBuilder, so the compiler knows what it is when you use it in the vector definition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文