Results 1 to 3 of 3

Thread: Problem with class variable in inheritance

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    2

    Post Problem with class variable in inheritance

    Class one has the variable "float ops[3]" and it uses it through out the class. Class two has the variable "float ops[4]" and class two inherits class one. From class two, how do i make anything in class one that uses ops[3] use class two's ops[4]? Let me know if further explanation is needed.
    Chimpy

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    You need to declare ops[4] as public or protected variable in class1 once.

    Your derived class2 can use it.

    I don't think it is possible to have 2 same variable name in your case, your compiler will get confused which one you are refering.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It's possible, use explicit namespace qualifyers:
    Code:
    void Class2::somefunc()
    {
      ops[2] = 3.2; // Class2::ops
      Class1::ops[1] = 18.6; // inherited Class1::ops
    }
    It might be necessary to write Class2:ps, in case the compiler reports ambiguity errors.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width