answersLogoWhite

0


Best Answer

C++ features a fundamental shift away from the structured programming principles of C. It introduces Object-Oriented-Programming(OOP) to the C language. However, C++ is a wholly new language, even though it is not fully object-oriented like Java and Smalltalk. C++ lets the user choose to program in the paradigm of his choice, but it is obviously advantageous to program in OOP, since it is more equipped to tackle real-world and complex problems. Also, code done using OOP can be more easily maintained, debugged, scaled and distributed. Other advantages of C++ are that it adds even more class-libraries to C. The header files of C++ also provide more built-in functions. On the whole, C++ syntax is also much more cleaned up than C, particularly in console I/O, structures and pointers.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

A class is simply a data type primarily used as a storage container. Each instance of the class is an object and each has its own discrete set of variables (instance member data). However, the class itself can store data of its own (static member data).

Class also have methods (functions) associated with them. However, unlike data, there is only one physical instance of each method, whether the method is a static or instance method. The only real difference between the two is that instance methods have a hidden argument, the this pointer, while static methods do not. This mechanism allows an object's methods to refer to the object itself.

Static member methods can only refer to other static members (both methods and data) but they can gain access to instance methods if an object of the class is passed to the method or is instantiated by the method. Instance methods have access to all members, whether static or instance, including members of other instance of the class.

Every class must have one or more constructors, at least one assignment operator and only one destructor. Constructors are special methods that are used to initialise the instance member data. Although they have a function body much like any other method, there is no return value (not even void). However, constructors also have an initialisation list that is automatically executed before the function body. If no list is specified, the compiler generates one automatically. However, if your class includes pointers, you must explicitly initialise them so they point to something valid.

Constructors cannot be called directly -- they are invoked automatically whenever an object of the class is instantiated. Behind the Scenes, a contiguous block of memory is allocated to accommodate all of the object's member data. The initialisation list then creates references within that block for each data member and initialises the memory accordingly. Finally, the constructor body is executed. In most cases the constructor body will be empty, but it can be used to initialise member data that cannot be fully initialised by the initialisation list alone. Using the constructor body to perform initialisation is less efficient as you're effectively initialising those members twice (once during instantiation and again in the constructor body), but in some cases this may be unavoidable.

If construction succeeds, you will end up with a reference or a pointer to the object, depending on whether the object is instantiated on the stack or the heap, respectively. Static objects will always succeed if compilation succeeds, but dynamic objects will result in a NULL pointer upon failure. If construction should fail within the constructor's method, however, the method show ideally throw an exception. A valid object can only exist if the construction succeeds.

Most classes will have a copy constructor which allows objects to be copied automatically. The compiler will generate one for you if you do not declare your own but you must declare one if your object points to unshared dynamic memory, otherwise the two copies will share the same memory (which is only practical with smart pointers). In order to copy objects you must have at least one other constructor in order to instantiate an object from scratch. If you do not declare any constructors, the compiler generates a default constructor for you (one with no arguments) as well as a copy constructor. If you declare any constructors, you lose the compiler-generated default constructor. Modern implementations of C++ also generate a move constructor, which allows the members of an existing object to be swapped with a new object, thus giving the new object ownership of the existing object's resources.

The compiler will also generate a destructor for you, but if your objects point to dynamic memory you must declare your own destructor in order to release that memory. Destructors are called automatically whenever an object falls from scope. Static objects will fall from scope automatically, but dynamic objects must be manually deleted when they are no longer required.

The compiler also generates an assignment operator which is similar to a copy constructor except you are assigning an existing object's members to another existing object rather than to a new object. As with the copy constructor, if your objects use pointers to unshared dynamic memory, you must explicitly declare your own assignment operator to ensure the memory is deep-copied. If you fail to do so, both objects end up pointing to the same memory, which would be disastrous if one should fall from scope.

while the destructor is used to release any instance member resources (dynamic memory) consumed by the class. If no constructors are declared, the compiler will generate a default constructor (one that accepts no arguments) and a copy constructor (one that accepts a constant reference to an existing instance of the class). If you declare any constructor, you automatically lose the default constructor. Similarly, if no destructor is declared, the compiler will generate one for you.

Every member can be assigned one of three visibility modes: private, protected and public. Private members are only accessible to the class and to friends of the class. Protected members are the same as private members but are also accessible to derivatives of the class. Public members are accessible to all code.

Friends of a class can either be external functions, class methods or entire classes. Friendship can only be determined by the class itself and cannot be inherited by derived classes. That is, every class must declare its own friends.

Inheritance allows new classes to be derived from existing classes. The new class (the derivative) inherits all the protected and public members of the existing class (the base class), except for its constructors and its destructor. Classes that are intended to act as base classes must have a virtual destructor to ensure that the most-derived class is always destroyed before its base classes are destroyed, regardless of which class in the hierarchy falls from scope first. Similarly, all methods that may be overridden by derivatives must be declared virtual in the base class to ensure the most-derived method is always invoked first, thus ensuring expected behaviour. Virtual methods work by creating a virtual table for each class in the hierarchy. The virtual table maps each virtual function to a function pointer. In this way it is not necessary to know the runtime type of a derivative in order to invoke specialised behaviour. Although you could use runtime type information to achieve the same end, it is much slower and costs a lot more memory than a virtual table.

Some classes are purely conceptual, not real objects. For instance, while squares and circles are real objects, they are both based on the concept of a shape. But a shape isn't a real object, it is an abstraction. Squares and circles share some common features, such as colour attributes and drawing methods but you cannot draw a shape unless you know the type of shape you are drawing. Therefore it makes no sense to instantiate objects of type shape, but it does make sense to use a shape object to provide a common interface to any type of shape. To cater for this, virtual methods can be declared pure-virtual. What this means is that the shape class can declare virtual methods such as draw() but it need not provide any implementation -- the implementation must be provided by the derivatives of shape. When we declare a pure-virtual method we automatically create an abstract base class (or abstract data type). This means we cannot instantiate a shape object other than by deriving from shape. The abstract base class then exists purely to provide a common interface to all its derivatives, but cannot be instantiated in its own right.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

It's not clear what you intend to secure, but no language that I know of has built-in security features. The language merely provides you with the building blocks and the basic tools required to write programs. You, the programmer, are entirely responsible for your program's security features -- whatever they may be. Thus you must write code to cater for it. There is no one-size-fits-all solution to security, however there are many custom-built classes and add-ons that you can modify to suit virtually any purpose, many of which are also available through open-source channels. Your IDE will probably include some standard security features such as data encryption classes and password entry classes, but they are not considered built-in features of the language itself.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

The main features of C++ is its object-oriented aspects. Object-oriented languages allow you to represent anything as a software object. Object-oriented languages allow you to develop programs quicker and more efficiently and also add more security to your programs than procedural languages.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

The main feature of any C++ program is the object-oriented programming paradigm (OOP). A C++ program without OOP is essentially just C, but is often known as C-style program due to minor syntax differences with C itself. C++ also has stricter type-safety.

C++ programs often make use of a combination of OOP and C-style programming, however OOP enables more complex programming with greater ease, robustness and scalability.

The four main pillars of OOP are encapsulation, inheritance, polymorphism and abstraction, all of which are supported by C++ through the use of classes. A class is a type definition from which objects can be instantiated, thus an object is an instance of a class. The struct keyword (which was inherited from C) can also be used to define classes, although most programmers use a struct purely for backward compatibility with C programs.

A class is much like a C-style struct insofar as it allows one or more data fields (data members) to be combined into a single entity. However classes can also include functions (member methods), and access to the functions and data can be strictly controlled to produce up to three separate interfaces: the private interface which is only accessible to the class itself, the protected interface which is accessible to derivatives of the class, and the public interface which is accessible to all code. It is these interfaces which allow consumers to interact with the object, such that the object becomes a self-contained entity, encapsulating all the functionality necessary to operate upon the data, whilst ensuring the data remains in a valid state at all times. Classes also have special methods known as constructors which are automatically invoked whenever an object is instantiated, in addition to a destructor which is automatically invoked when an object falls from scope. The purpose of the constructor is to initialise the data members, while the destructor can be used to release resources consumed by the object when it falls from scope.

Inheritance allows new classes to be derived from existing classes, enabling code re-use. The derived classes inherit the public and protected interfaces of their base classes (the existing classes), and can override methods in the base class to provide more specific implementations in the derived class. Derivatives may also expose their own interfaces. However, in order to ensure the most-derived override is called when invoked from within a base class, override-able methods must be declared virtual in the base class. And to ensure object hierarchies are destroyed in the correct sequence (from most-derived to least-derived), the destructor must also be declared virtual. Construction always works in the opposite direction thus constructors can never be declared virtual. Since derived objects cannot be instantiated until its base classes are fully constructed, virtual functions invoked by constructors are treated just as if they were non-virtual during the instantiation of each object.

Inheritance and the virtual interfaces enable polymorphic behaviour. That is, every derived class has an "is-a" relationship with its base classes. In other words, a derived class is said to be a "kind of" base class -- a more specialised version of its base classes. Thus any derived object can be passed to a function that expects an instance of one of its base classes. Meanwhile, the virtual interface ensures that the base class behaves according to its runtime type -- its actual derived type -- thus ensuring correct behaviour even when the runtime type cannot be known during compile time. This is achieved via a v-table, or virtual table. The v-table maps virtual functions to actual functions through a table of function pointers. Every class that declares or inherits a virtual function automatically generates a v-table. While this mechanism uses a little extra memory, the only alternative would be to employ runtime type information which is far more expensive in terms of both memory consumption and performance.

The final pillar, abstraction, primarily relates to abstract data types (ADTs), classes which are purely conceptual rather than real. For instance, a shape can be considered a conceptual class whereas a square or circle can be considered actual classes. That is, while you can instantiate a square or a circle, you cannot physically instantiate a shape because it is an abstraction -- a non-shape if you will. However, a shape class can encapsulate an interface that is common to all shapes, such as a draw method, or a rotate method. In some cases it may even be able to provide a generic implementation for those methods (a virtual method) but even if it cannot, it can still declare the method -- a pure virtual method. Unlike a virtual method which may be overridden, a pure virtual method must be overridden. If an object contains at least one pure virtual method then it is automatically an ADT, and the only way to instantiate an ADT is through inheritance. The derivative must provide a complete implementation for the abstract interface otherwise it becomes an ADT itself. However, any implementations that it does provide are then regarded as being virtual with respect to further derivatives, thus those implementations can be inherited. If the class that declared the pure virtual method also provides a generic implementation, that implementation cannot be inherited, but it can still be called from an override.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

C++ is an object oriented programming language. Hence it provides the following features:

1) Polymorphism

2) Inheritance

3) Encapsulation

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Everything C has to offer, plus object-oriented programming and an extensive library of pre-defined objects and templates.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the different features of c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Do I need features of c plus plus?

No.


What is the difference between cc plus plus and c sharp?

C# is inherited from c++ with some additional features


What are the features of C plus plus that surpass C?

Object-oriented programming and stricter type-safety.


What is the different between turbo c plus plus and unix c plus plus?

There is no such thing as 'unix C++'.


Is the syntax between c and c plus plus different?

Yes


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 is the different of c and c plus plus?

c is procedure oriented and c++ is object oriented & much newer.


What are the most prominent features of C plus plus?

Object oriented programming. General purpose. Cross-platform.


What is the different between Compiler and Interpreter in C or C plus plus programming?

It is easy to tell: there is no interpreter for C and C++, they are compiled languages.


Does C plus plus compiler will compile C in programming?

Yes we can compile a c program using c++ compiler. Because c++ evolved from the c. c++ have some additional features beyond c. c++ support almost all concepts used in c.


How C plus plus is better than C?

C++ is a language code for computer and lapatops which is used in programming but C is a grade so they are different.


What is different of c language and c plus plus?

Primarily OOP support, but there are minor syntax difference. By and large anything you can do in C you can also do in C++.