answersLogoWhite

0

C++ of course uses classes (class) as opposed to structures (struct) for the purpose of keeping data members with an implicit 'private' access specifer as opposed to data members being 'public' by default (as with a struct.) Unless use of external C libs or routines are mandatory and wrapped in the appropriate C header(s), I don't know of any reason to use a struct anywhere in C++.

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

What is the name of the structure type in C plus plus?

The same as in C, struct.


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 { // ... };


Write a c plus plus programme to illustrate single inheritance?

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


Sample code of typedefstruct in c plus plus?

You don't need a typedef to declare a struct in C++. A struct is declared exactly the same way that you would declare a class, the only difference being that struct members are public by default, while class members are private by default. Aside from that the class and struct keywords are completely interchangeable.


Can you give an example of a structure in C plus plus?

struct point { int x; int y; };


Similarities between C plus plus struct and class?

The only difference between a struct and a class in C++ is that struct members are public by default while class members are private by default. Other than that they act and behave in exactly the same way and are both used to define classes. By convention, struct is used exactly as it would be used in C, with all public members and no member functions, to provide backward compatibility with C-style code.


Program for new and delete operator using c plus plus?

#include<iostream> struct object { int m_data; }; void main() { object obj=new object; obj.m_data = 42; delete( obj ); return( 0 ); }


Can you program games with c plus plus?

Yes, you can program games with C++.


What is a class in c plus plus how does it compare with structure in c?

A struct in C is a POD (plain old data) type. A class in C++ can also be a POD for backward compatibility with C code, but more typically combines data with methods that operate upon the data, including constructors and initialisers. Classes in C++ can be declared using either the struct or class keyword. By convention you will typically use struct to define POD data types and class to define more complex data types. The only practical difference between a struct and a class is that classes use private access and inheritance by default while struct uses public access and inheritance by default. Thus the following two class definitions are functionally the same: struct A { A():m_data(0) {} // public access by default private: int m_data; }; class B { int m_data; // private access by default public: B():m_data(0) {} };


Is there a limit to nesting of structure?

Yes: only completely defined structured can be included (that doesn't include the actual structure itself). Example: struct a; struct b { int b1; }; struct c { struct a; /* BAD */ struct b; /* OK */ struct c; /* BAD */ };


How can you check if the OS the program is running on is vista or xp in c?

Use the Win32 function call GetVersionEx. It has as an argument a OSVERSIONINFOEX struct. The dwMajorVersion value for the struct will be "5" for XP, "6" for Vista.


What is the sort cut for running c plus plus program?

It depends on the particular IDE. Visual Studio uses <Ctrl>F5 to start a program in non-debug mode, and F5 to start a program in debug mode.