C++ compiler thinks my constructor definition is a method

2.3k views Asked by At

I'm getting the following errors:

C:\Users\James\cavewhere\dewalls\src\unit.cpp:6: error: C2511: 'dewalls::Unit::Unit(QString,dewalls::UnitType *)' : overloaded member function not found in 'dewalls::Unit'
C:\Users\James\cavewhere\dewalls\src\unit.cpp:9: error: C2550: 'dewalls::Unit::{ctor}' : constructor initializer lists are only allowed on constructor definitions

unit.h:

#ifndef UNIT_H
#define UNIT_H

class UnitType;

#include <QString>

namespace dewalls {

class Unit
{
public:
    Unit(QString name, UnitType *type);

private:
    QString _name;
    UnitType *_type;
};

}

#endif // UNIT_H

unit.cpp:

#include "unit.h"
#include "unittype.h"

namespace dewalls {

Unit::Unit(QString name, UnitType *type) :
    _name(name),
    _type(type)
{

}

}

What for the love of god am I doing wrong?

1

There are 1 answers

2
Cory Kramer On BEST ANSWER

Looks like UnitType should be in your namespace too

namespace dewalls {
    class UnitType;
}