|
-
Sep 25th, 2002, 02:45 AM
#1
Thread Starter
New Member
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.
-
Sep 25th, 2002, 04:29 AM
#2
Hyperactive Member
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.
-
Sep 25th, 2002, 08:01 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|