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]
Other format: [Raw text]

Re: [Bug c++/26062] New: "Class object();" is not interpreted as a call to default constructor


sylvain dot joyeux at m4x dot org wrote:
The following testcase

#include <iostream>

bool flag = true;
class guardian
{
public:
    guardian() { flag = false; }
    ~guardian() { flag = true; }
    bool get() { return flag; }
};

int main()
{
    guardian guard();
    std::cout << guard.get() << std::endl;
    std::cout << flag << std::endl;
}

Leads to the error
error: request for member 'get' in 'guard', which is of non-class type
'guardian ()()'

FWIW, here's the HP aCC 3 error message for this program. Does it make it clear where the problem is?

Error 583: "t.cpp", line 15 # Left side of '.' requires a class object; type found was a function 'guardian ()'. Did you try to declare an object with a nested constructor call? Such a declaration is interpreted as a function declaration "guardian
guard()" ["t.cpp", line 14].
std::cout << guard.get() << std::endl;
^^^^^


Martin


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