answersLogoWhite

0


Best Answer

A Constructor is called when you are making a new instance of a class and member functions are functions that you can call within your class or else call using the instance of that class.

for example


class Foo {


public:

int bar;

Foo(int bar) {this->bar = bar;}

inc_bar(); {this->bar++;}

};


Foo instance(10); // Constructor is called and bar is set to 10

cout << instance.bar << endl;

instance.inc_bar(); // call the member function to increment bar

cout << instance.bar << endl;

User Avatar

Wiki User

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

Wiki User

14y ago

Constructor creates an instance of class, destructor destroys it.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

A constructor creates the initial state of a collection of data. A function modifies or queries the data after it has been initialized.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is difference constructor and function in programming C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between constructor and friend function in c plus plus?

A constructor is a method that fires when the object is instantiated. A friend function is a function that has special access to the object. They are two different types of things, and cannot be further differenced.


What is the difference between implicit and explicit call of constructor in c plus plus?

An implicit constructor call will always call the default constructor, whereas explicit constructor calls allow to chose the best constructor and passing of arguments into the constructor.


True or False A C plus plus class constructor cannot return a function value?

True - A C++ constructor cannot return a value.


What is the use of private constructor in c plus plus?

Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.


How do you correct the C plus plus programming error missing function header?

You need to #include the header file that contains the missing function's declaration.


How do you invoke the constructor function in c plus plus?

There is no such thing as a constructor function in C++ (constructors have no return value, not even void, and cannot be called like regular functions). Constructors are invoked rather than called directly, either by declaring a static variable of the class type, or via the C++ new operator.


How do you convert numeric value into alpha value in c plus plus programming language?

use the _itoa function


What is the first function executed in a C plus plus program?

For gcc there's a non-standard solution. Declare the function with __attribute__((constructor)) (note the double parentheses). Like this: void init(void) __attribute__ ((constructor)); void init(void) { // your code goes here } Starting with gcc 4.3 there's even a possibility to assign a priority to the "constructor". See http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html for details.


What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


Can you write own constructor in c plus plus?

Yes.


What is swap in c plus plus programming language?

It is not a reserved word, so can be an identifier (name of a type/variable/function).


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

B. Class.