answersLogoWhite

0

A nested structure is simply one structure inside another. The inner structure is local to the enclosing structure.

struct A { struct B {}; };

Here, we can instantiate an instance of A as normal.

A a;

But to instantiate B we must qualify the type because it is local to A:

A::B b;

If B were only required by A, then we can prevent users from instantiating instances of B simply by declaring it private:

struct A { private: struct B {}; };

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

What is nested class in c plus plus?

s.


Can you use c in c plus plus without using class and object?

Sure.


How do you calculate the size of a class in memory in C plus plus?

Use sizeof( ).


What do you understand by a Nested Class?

A nested class is a class that is declared within the scope of another class, the enclosing or outer class. class A // enclosing class { public: class B {}; // nested class }; Note that although class B is declared public in this example, keep in mind that it is still scoped to class A. Therefore the following code will fail to compile: int main() { B b; // Compiler error! } Instead, you must use scope resolution: int main() { A::B b; // OK } If class B were declared private to class A, then only class A and friends of class A have access to class A::B. If declared protected, accessibility extends to derivatives of class A. Nested classes may also inherit from other nested classes within the same enclosing class. class A { class B {}; class C : public class B {}; }; Keep in mind that nested classes are scoped to the enclosing class and are primarily used to reduce the visibility of the nested class, particularly when combined with private or protected access. When you have a class that is only of relevance to the enclosing class, this makes perfect sense. However, if the nested class is declared public, you have the option of using an embedded object or a nested class. But the point of scope resolution is in order to reduce the chances of programmer errors, particularly when using two or more classes with the same name but with different implementations.


What is an instance class in C plus plus?

You have a class(i.g. MyClass): class MyClass{ public: int MyData; }; And then you use the class like this: int main(){ MyClass MyObject; MyObject.MyData=7; }


Can a c plus plus class be derived from a Java class?

No.


What is the role of object in c plus plus?

An object in C++ is an instance of a C++ class.


What is the difference between n-- and --n in C plus plus statement?

If these expressions are stand-alone (not nested), then they do the same thing, ie increment 'n'.


What is the compound in c language?

compound c language is complicated where we need to use many nested functions and loops


Can include files be nested in c?

Yes, include files can be nested in C and C++. In fact, most library implementations do just that.


How do you do nested strcutres program in c plus plus?

As its name suggests, a nested structure is a structure which contains another within it. Here is an example in which the "nApple" structure is nested withing the "nTree" structure: #includestruct nApple{int stem;int skin;};struct nTree{int leaves;nApple redDelicious;nApple grannySmith;};


What is the unit of programming in c plus plus A. Function B. class C. object D. Attribute?

B. Class.