This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Strange warnings


Ryszard Kabatek <rysio@rumcajs.chemie.uni-halle.de> writes:

| In the sample below the class X should have a standard constructor
| generated by the compiler. But I get the following warnings:
| 
| # eg++ x.cc
| x.cc:6: warning: `class X' only defines private constructors and has no
| friends
| x.cc: In function `static class X * X::create()':
| x.cc:5: no matching function for call to `X::X ()'
| x.cc:3: candidates are: X::X(const X &)

EGCS gets it right. The Standard says:

12.1/5
---
  A default constructor for a class X is a constructor of class X that 
  can be called without an argument. If there is no user-defined
  constructor for class X, a default constructor is implicitly
  declared ...
---

Since you declared X::X(const X&), the default constructor is not
implicitly declared and it is up to you do so and give it a semantic.


| The first warning I get too if I define a private standard constructor.
| But there is a static function, that creates new instances of X,
| class X does not need friend functions or classes.

It is two way :-) : it can be helpful and quite inappropriate.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]