简体   繁体   中英

g++ error - expected unqualified-id before ')' token

When I go to compile this code it says it expected an unqualified-id before the ) in my constructor

analysis2.h:

#ifndef _ANALYSIS2_H
#define _ANALYSIS2_H

class Analysis2{

public:

    Analysis2();
...

analysis2.cpp:

#include "analysis2.h"

using namespace std;

Analysis2()
{
    Seconds_v = 0;
    Seconds_t = 0;
}
...

How do I fix this?

In analysis2.cpp you need to tell the compiler that you are defining the constructor by giving it a scope:

Analysis2::Analysis2()
{
    Seconds_v = 0;
    Seconds_t = 0;
}

Scope Resolution Operator

In analysis2.cpp , write this:

Analysis2::Analysis()
{
    Seconds_v = 0;
    Seconds_t = 0;
}

You have to include the class name ( Analysis2:: ).

You need to specify Analysis2::Analysis2() if you are trying to define a constructor. Otherwise, the compiler supposes that the Analysis2 is the name of a type in a declaration of something else.

Type

Analysis2::

before the method name or constructor/destructor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM