explict keyword for empty constructors ?

G

Ganesh Gella

Hi All,

While going through xalan's XSLT source code, I came across few
constructors which are qualified as "explicit". These constructors are
empty constructors.

I read about the use of explict when constructors accept single
argument and it is to avoid accidental conversion from parameter type
to class type.

I am unable to find the significance of explicit keyword for a
constructor that does not accept any arguments all.

Can any of you throw more light on this please ?

For example,

class XalanDOMString
{
explicit XalanDOMString();
};
 
V

Victor Bazarov

Ganesh said:
While going through xalan's XSLT source code, I came across few
constructors which are qualified as "explicit". These constructors are
empty constructors.

You mean, "default constructors", I gather.
I read about the use of explict when constructors accept single
argument and it is to avoid accidental conversion from parameter type
to class type.

I am unable to find the significance of explicit keyword for a
constructor that does not accept any arguments all.

Can any of you throw more light on this please ?

For example,

class XalanDOMString
{
explicit XalanDOMString();
};

There is no significance. A few months back there was a discussion on
this subject in c.l.c++.m and the result, IIRC, was that 'explicit' has
no effect on a c-tor with the number of arguments other than 1.

V
 
R

Ron Natalie

Ganesh said:
I am unable to find the significance of explicit keyword for a
constructor that does not accept any arguments all.

As near as I know, it's not illegal to say "explicit" there.
It however, has no defined behavior on any constructor that
isn't a converting constructor (one that can be called with
exactly one args, including multiarg'd constructors that have
defaulted args).
 
R

Ron Natalie

Victor said:
There is no significance. A few months back there was a discussion on
this subject in c.l.c++.m and the result, IIRC, was that 'explicit' has
no effect on a c-tor with the number of arguments other than 1.
It can have an effect on constructors that take more than one
argument:
class T {
public:
explicit T(int a, int b = 0);
};

The constructor above would be a converting constructor without the
explicit qualifier.
 
I

Ioannis Vranos

Ganesh said:
Hi All,

While going through xalan's XSLT source code, I came across few
constructors which are qualified as "explicit". These constructors are
empty constructors.

I read about the use of explict when constructors accept single
argument and it is to avoid accidental conversion from parameter type
to class type.

I am unable to find the significance of explicit keyword for a
constructor that does not accept any arguments all.

Can any of you throw more light on this please ?

For example,

class XalanDOMString
{
explicit XalanDOMString();
};



If you think more on it, you will realise that all other constructor
uses are explicit (including the default constructor).
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top