C++/C++

Advertisement


Question
1.Three objects are there of  a single class.suppose a1,a2,a3.
There is a statement in main function like a1=a2=a3.
but question what mechanism i will folllow so that value of a3 will not come a1.but value of a3 will come to a2.

2.why static function can only access only static variable in c++.

Answer
Hi,
 I have no idea about 1 and if you get any then do inform me at dharmender.rai@csfb.com

for 2, static things are not any object specific. They are class-specific. They are created well-before any object of that class is created. So if you try to access any non-static member variable from the static function then this could create the issue as you could use the static function from outside (without using any object and also before any object is created). There could be no way of knowing which object you are refering to (first case) and there would be no object (case 2).

Thanks,
RaiD

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Dharmender Rai

Expertise

I can answer general and system level C/C++ questions.

Experience

I have 5 years of experience in C++.

©2016 About.com. All rights reserved.