Strange warnings

Gabriel Dos_Reis Gabriel.Dos_Reis@sophia.inria.fr
Wed May 5 05:45:00 GMT 1999


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


More information about the Gcc-bugs mailing list