valid C++

Discussion in 'C++' started by Marc Schellens, Jan 14, 2005.

  1. gcc 3.4 complains when a
    derived class uses an indentifier which is
    defined in the base class and the base class
    is the template parameter.

    eg. something like:

    class B
    {
    protected:
    int member;
    };

    template< class base>
    class D: public base
    {
    public:
    void aFun();
    };

    template< class base>
    void D< base>::aFun()
    {
    member = 1;
    }

    template class D< B>;

    It says then:
    member undecalred (first use of this function).


    Isn't that valid C++?

    thanks,
    marc
     
    Marc Schellens, Jan 14, 2005
    #1
    1. Advertising

  2. Marc Schellens

    Sharad Kala Guest

    Sharad Kala, Jan 14, 2005
    #2
    1. Advertising

  3. * Marc Schellens:
    > gcc 3.4 complains when a
    > derived class uses an indentifier which is
    > defined in the base class and the base class
    > is the template parameter.
    >
    > eg. something like:
    >
    > class B
    > {
    > protected:
    > int member;
    > };
    >
    > template< class base>
    > class D: public base
    > {
    > public:
    > void aFun();
    > };
    >
    > template< class base>
    > void D< base>::aFun()
    > {
    > member = 1;
    > }
    >
    > template class D< B>;
    >
    > It says then:
    > member undecalred (first use of this function).
    >
    > Isn't that valid C++?


    No, but older compilers may accept it (also, VC 7.1 accepts it).

    The problem is that when seeing 'member = 1' for the first time the
    compiler doesn't have the slightest cue about where 'member' comes from,
    or whether it comes from anywhere.

    To give it that clue you can use a 'using' statement in class D,
    or you can qualify 'member' in some way, e.g. 'this.member'.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 14, 2005
    #3
  4. Marc Schellens

    Sharad Kala Guest

    "Alf P. Steinbach" <> wrote in message

    > * Marc Schellens:
    > To give it that clue you can use a 'using' statement in class D,
    > or you can qualify 'member' in some way, e.g. 'this.member'.


    Of course you must have meant this->member.
     
    Sharad Kala, Jan 14, 2005
    #4
  5. * Sharad Kala:
    >
    > "Alf P. Steinbach" <> wrote in message
    >
    > > * Marc Schellens:
    > > To give it that clue you can use a 'using' statement in class D,
    > > or you can qualify 'member' in some way, e.g. 'this.member'.

    >
    > Of course you must have meant this->member.


    Thanks. I shall curse 4 million times before next compiling C#.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 14, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aschel Kritsos

    Valid file types

    Aschel Kritsos, Nov 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    613
  2. Ajit
    Replies:
    1
    Views:
    3,660
    Victor Garcia Aprea [MVP]
    Apr 24, 2004
  3. CT

    vbc is not valid command

    CT, Oct 30, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    2,899
  4. Pial
    Replies:
    6
    Views:
    52,503
    Nassos
    Apr 28, 2005
  5. MM
    Replies:
    3
    Views:
    457
    Kai Harrekilde-Petersen
    Jun 19, 2004
Loading...

Share This Page