gcc 4 can not resolve member var derived from base class in atemplate class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve yee

    gcc 4 can not resolve member var derived from base class in atemplate class

    #include <iostream>
    #include <list>

    template<class mt_policy>
    class Base
    {
    public:
    int a;
    };

    template<class mt_policy = int>
    class signal0 : public Base<mt_policy>
    {
    public:
    void aaa()
    {
    std::cout<<"a = "<<a<<std::endl ;
    }
    };

    int main()
    {
    signal0<intp;
    p.aaa();
    }
    ~

    test.cpp: In member function ‘void signal0<mt_poli cy>::aaa()’:
    test.cpp:17: error: ‘a’ was not declared in this scope
  • acehreli@gmail.com

    #2
    Re: gcc 4 can not resolve member var derived from base class in atemplate class

    On Jul 1, 9:05 am, steve yee <yiton...@gmail .comwrote:
    #include <iostream>
    #include <list>
    >
    template<class mt_policy>
    class Base
    {
    public:
    int a;
    >
    };
    >
    template<class mt_policy = int>
    class signal0 : public Base<mt_policy>
    {
    public:
    void aaa()
    {
    std::cout<<"a = "<<a<<std::endl ;
    This is the definition of class template signal0, not an instantiation
    of it. So the compiler cannot know whether any Base<mt_policyw ill
    provide an 'a'. For example, some specialization may not have an a.

    The compiler cannot assume that a missing name will be available
    through a templated base. What if there were two bases?

    The solution is to fully qualify 'a': Base<mt_policy> ::a
    }
    >
    };
    >
    int main()
    {
    signal0<intp;
    p.aaa();}
    >
    ~
    >
    test.cpp: In member function ‘void signal0<mt_poli cy>::aaa()’:
    test.cpp:17: error: ‘a’ was not declared in this scope
    Ali

    Comment

    • Juha Nieminen

      #3
      Re: gcc 4 can not resolve member var derived from base class in atemplate class

      steve yee wrote:
      test.cpp: In member function ‘void signal0<mt_poli cy>::aaa()’:
      test.cpp:17: error: ‘a’ was not declared in this scope
      You have to add this to your signal0 class:

      using Base<mt_policy> ::a;

      I don't remember now why this was standardized like that.

      Comment

      • steve yee

        #4
        Re: gcc 4 can not resolve member var derived from base class in atemplate class


        so this is a standard, not a bug of gcc? but vc9 can compile it.


        On Jul 2, 2:00 am, Juha Nieminen <nos...@thanks. invalidwrote:
        steve yee wrote:
        test.cpp: In member function ‘void signal0<mt_poli cy>::aaa()’:
        test.cpp:17: error: ‘a’ was not declared in this scope
        >
          You have to add this to your signal0 class:
        >
        using Base<mt_policy> ::a;
        >
          I don't remember now why this was standardized like that.

        Comment

        • Juha Nieminen

          #5
          Re: gcc 4 can not resolve member var derived from base class in atemplate class

          steve yee wrote:
          so this is a standard, not a bug of gcc? but vc9 can compile it.
          VC9 doesn't obey the standard in all respects.

          Comment

          • Kyle

            #6
            Re: gcc 4 can not resolve member var derived from base class in atemplate class

            steve yee wrote:
            #include<iostre am>
            #include<list>
            >
            template<class mt_policy>
            class Base
            {
            public:
            int a;
            };
            >
            template<class mt_policy = int>
            class signal0 : public Base<mt_policy>
            {
            public:
            void aaa()
            {
            std::cout<<"a ="<<a<<std::end l;
            here you need to make name 'a' dependent on template parameter
            one of ways to do this, is to access 'a' through this pointer:

            std::cout<<"a ="<<this->a<<std::endl ;
            }
            };
            >
            int main()
            {
            signal0<int p;
            p.aaa();
            }
            ~
            >
            test.cpp: In member function ‘void signal0<mt_poli cy>::aaa()’:
            test.cpp:17: error: ‘a’ was not declared in this scope

            Comment

            • Bo Persson

              #7
              Re: gcc 4 can not resolve member var derived from base class in a template class

              Juha Nieminen wrote:
              steve yee wrote:
              >so this is a standard, not a bug of gcc? but vc9 can compile it.
              >
              VC9 doesn't obey the standard in all respects.
              It does respect this, if you ask it too (option /Za). Default is to
              compile old, pre-standard, Windows code.


              Bo Persson


              Comment

              Working...