answersLogoWhite

0

Yes. A C++ struct is exactly the same as a C++ class. The only difference is that struct members are public by default, whereas class members are private by default. Other than that, they work exactly the same way. Typically, you will use a struct when there is no need to encapsulate the data members (public access only), or when you need backward compatibility with C-style code. A C-style struct has only public data members (none of which can be a class of course, but may be another struct), but it has no methods whatsoever. Thus you need to disable the compiler-generated default and copy constructors, the destructor and the assignment operator. This is achieved by declaring them without a function body (no curly braces).

User Avatar

Wiki User

11y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions

What are the main features of OOP in c plus plus?

The main features of OOP are the same regardless of the language. They are: encapsulation; data hiding; inheritance; and polymorphism.


What are the various concepts of c plus plus?

1.Classes and Objects 2.Constructors and Destructors 3.Inheritance 4.Polymorphism 5.Dynamic Binding


What are the concepts of object oriented programming in c plus plus?

The concepts of OOP in C++ are the same as for OOP in any other programming language: abstraction, encapsulation, inheritance and polymorphism.


Is overriding a dynamic polymorphism in c plus plus or not?

In C++, overriding and function, method, or operator is a different thing than (dynamic) polymorphism, so overriding a polymorphic method is almost entirely possible.


How ploymorphism and inheritance is different from that in Java and c plus plus?

C++ allows multiple inheritance while Java does not. In my opinion, multiple inheritance is not useful because it can get very confusing very quick. For polymorphism, C++ does early binding by default, while Java does late binding by default. Late binding is more useful than early binding.


Why c plus plus is not complete object oriented language?

because c++ supports all the basic concepts of oop :1.objects,2.classes,3.data abstraction and encapsulation,4.inheritance,5.polymorphism,6.dynamic binding,5.message passing.


Why is C plus plus called an object oriented language?

It is called an OOP language because it supports the four pillars of the OOP paradigm: abstraction, encapsulation, inheritance and polymorphism. However, it is not 100% object oriented as it also supports the concept of primitive variables, including pointers, which are not implemented as objects.


How does c plus plus endeavor to represent the object oriented paradigm?

C++ endeavours to represent the object oriented programming paradigm through the use of classes. The four main pillars of OOP are encapsulation, inheritance, polymorphism and abstraction, which C++ primarily achieves through the use of classes, class hierarchies, virtual methods and templates.


Does c plus plus supports hierarchical inheritance?

Yes.


Write a c plus plus programme to illustrate single inheritance?

struct A {}; // base class struct B : A {} // derived class (single inheritance).


How can a constructor be invoked at the time of inheritance in C Plus Plus?

It cannot. Inheritance is a compile-time operation. Constructors are invoked at runtime at the point of instantiation.


Demonstrate single inheritance in C plus plus?

struct base1 { // ... }; struct base2 { // ... }; struct derived1 : public base1 // single inheritance { // ... }; struct derived2 : public base1, public base2 // multiple inheritance { // ... };