answersLogoWhite

0

A C++ structure (struct) is simply a type of class where all members have public access by default (class members are private by default). Aside from that, C++ classes and structures have exactly the same meaning; the following definitions are exactly equivalent:

struct S {

int x; // public by default

private:

int y;

};

class C { public:

int x;

private:

int y;

};

Note that although the physical representations of S and C types are exactly equivalent, they are still fundamentally different types. That is, you cannot pass an object of type C into a function that expects an object of type S, unless you explicitly define a cast operator to perform an implicit conversion from C to S.

By convention you will typically use structures to define PODs ('plain old data' types where all members are implicitly public and the type is not itself derived from another non-POD type) and use classes when you need to establish an invariant. However, there's nothing in the language that fundamentally prevents you from using a structure to establish an invariant or to use a class as a POD. The only real disadvantage in doing so is that (conventional) C++ programmers may question why you would choose to do so; it can only lead to confusion.

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

What is structure and union?

Structure is a query that is used in language c++


Advantages of c language in cryptography?

You can use OpenSSL.


How do you create modules in c language?

by using structure in c.........


Why is c called a structured language?

a synonym for structure language in "Comb-sturctured" languages. C in comb.


What data structure is used to represent graphs in c language?

A tree.


What is the program language c?

C is a pop language. C is a case sensetive language. C is motherof all language. C is block structure language. C is a high level language. C is advace of B language. C developed by D.richties in 1972 at AT & T Bell lab in USA. Sachin Bhardwaj 986854722 skbmca@gmail.com


What is the difference between c and c plus plus extension?

c language is the structure oriented language and c does not follows the object oriented paradigms . c++ obeys the all object oriented language characteristics ========== C++ is a set of extensions to the C language to allow some (not all) principles of object-oriented programming to be used. Originally, C++ was a front end pre-processor for C and C++ compilers will translate C language functions.


What is basic structure of file handling in c language?

open, read/write, close


What the difference between c and c plus plus?

The fundamental difference is that in C++ object-oriented programming (OOP) was added. C is a procedural language (that means. top-down structure design), where as C++, which is an extension of C itself, is an object oriented language.


Example of procedural programming language and object oriented programming language?

example of procedural programming are those programming language that have structure e.g basic,fortran,c++,c and pascal e.t.c


How do you define the structure size in C language?

You cannot define the size of the structure, but you can query it with sizeof.The structure size in C language depends on the elements of the structure.Example:#include struct Test{int v;char str[100];};int main(){printf("The structure size is %d\n", sizeof(struct Test));return 0;}


'C'language is called block structure language why?

Because a C program is constructed via a series of "blocks" or functions. It is not an object oriented language.