Question 29: The C++ code below generates a compiler error. Which of the following solutions can be used to correctly access the

class SomeClass { public: int data; protected: class Nest { public: int nested; }; public: static Nest* createNest(){return new Nest;} }; void use_someclass() { SomeClass::Nest* nst = SomeClass::createNest(); nst->nested = 5; }

 

 

    A. Make function void use_someclass() a friend of class SomeClass.

    B. Make the function createNest() a non-static function of SomeClass.

    C. Declare the class Nest in public scope of class SomeClass.

    D. Make the object nst a reference object, and make the function createNest() return a Nest&.

    E. Derive a class from SomeClass. Make the object nst a derived class pointer so that it can access SomeClass's protected declarations.

 

 

 

 

A   C 

你可能感兴趣的:(C++,function,object,Class,Access,compiler)