使用“extern”类内部给了我“指定的存储类”错误

发布于 2025-01-19 00:59:37 字数 1151 浏览 3 评论 0原文

我正在尝试在全球范围内使用“Graph”变量。

我在没有“extern”的情况下在课堂上定义它没有问题, 但是当我添加“extern”时,它会出现以下错误。 错误和正确的使用方法是什么? 谢谢。

我收到的错误消息:

 error: storage class specified for ‘g2_’
                 extern Graph    g2_;
                                 ^~~

头文件:

namespace ompl
{
    namespace geometric
    {
        class AAA: public PRM   
        {
        public:
                        
            typedef boost::adjacency_list <
                boost::vecS, boost::vecS, boost::undirectedS,
                boost::property < vertex_state_t, base::State*,
                boost::property < vertex_total_connection_attempts_t, unsigned long int,
                boost::property < vertex_successful_connection_attempts_t, unsigned long int,
                boost::property < boost::vertex_predecessor_t, unsigned long int,
                boost::property < boost::vertex_rank_t, unsigned long int > > > > >,
                boost::property < boost::edge_weight_t, base::Cost >
            > Graph;

            extern Graph    g2_;
        };
    }
}

#endif

I'm trying to use "Graph" variable globally.

I have no problem defining it in class without 'extern',
but when I add 'extern', it gives following error.
What's wrong and right way to use it?
Thank you.

Error message I got :

 error: storage class specified for ‘g2_’
                 extern Graph    g2_;
                                 ^~~

Header File :

namespace ompl
{
    namespace geometric
    {
        class AAA: public PRM   
        {
        public:
                        
            typedef boost::adjacency_list <
                boost::vecS, boost::vecS, boost::undirectedS,
                boost::property < vertex_state_t, base::State*,
                boost::property < vertex_total_connection_attempts_t, unsigned long int,
                boost::property < vertex_successful_connection_attempts_t, unsigned long int,
                boost::property < boost::vertex_predecessor_t, unsigned long int,
                boost::property < boost::vertex_rank_t, unsigned long int > > > > >,
                boost::property < boost::edge_weight_t, base::Cost >
            > Graph;

            extern Graph    g2_;
        };
    }
}

#endif

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文