mrswmmr
mrswmmr

Reputation: 2141

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?

Upvotes: 2

Views: 19827

Answers (4)

James Kanze
James Kanze

Reputation: 153899

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.

Upvotes: 1

user663896
user663896

Reputation:

Type

Analysis2::

before the method name or constructor/destructor

Upvotes: 1

Jesper
Jesper

Reputation: 206786

In analysis2.cpp, write this:

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

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

Upvotes: 2

Chad
Chad

Reputation: 19609

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

Upvotes: 5

Related Questions