IS CONSTRUCTOR A SPECIAL MEMBER FUNCTION? OR SOMETHING ELSE HAVING THE SYNTAX OF FUNCTION?

I

infinity

Hi all,
Is constructor a special member function? But I don't think it is
either a member function or even a special member function although it
has the syntax of a function. I think it confused with a function due
to the similar syntax. If i am wrong give some proof and prove you
points. I think its a fundamental doubt.
~Thanks
Infinity
 
N

Neelesh Bodas

Hi all,
Is constructor a special member function? But I don't think it is
either a member function or even a special member function although it
has the syntax of a function. I think it confused with a function due
to the similar syntax. If i am wrong give some proof and prove you
points. I think its a fundamental doubt.
~Thanks
Infinity

The C++ standard chapter 12 paragraph 1 :

"The default constructor (12.1), copy constructor and copy assignment
operator (12.8), and destructor (12.4) are special member functions.
The implementation will implicitly declare these member functions for a
class type when the program does not explicitly declare them..."

Hence proved.
 
M

mlimber

Hi all,
Is constructor a special member function? But I don't think it is
either a member function or even a special member function although it
has the syntax of a function. I think it confused with a function due
to the similar syntax. If i am wrong give some proof and prove you
points. I think its a fundamental doubt.
~Thanks
Infinity

WHY ARE YOU YELLING AT US IN YOUR SUBJECT LINE?!

Constructors are special member functions. In particular, a constructor
does not get inherited and cannot be virtual. On the first point,
consider:

struct Base
{
Base( int );
void Foo();
};

struct Derived
{
Derived() : Base( 0 ) {}
};

void Bar()
{
//Derived d( 0 ); // Error! Cannot use Base's constructor

Derived d; // Ok. Use Derived's constructor
d.Foo(); // Ok. Foo is inherited, unlike Base::Base()
}

The destructor and assignment operator are also special.

Cheers! --M
 
G

Greg Comeau

Is constructor a special member function? But I don't think it is
either a member function or even a special member function although it
has the syntax of a function. I think it confused with a function due
to the similar syntax. If i am wrong give some proof and prove you
points. I think its a fundamental doubt.

A member function is a function, that's a member of a class.

A constructor is a member function.

It can also fall into the so-called category of "special" member function.
Section 12p1 of Standard C++ reads "The default constructor, copy
constructor and copy assignment operator, and destructor are
``special member functions''."

Is there some other underlying question about them though?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top