Search code examples
c++ubuntugccubuntu-17.04

expected constructor, destructor, or type conversion before ‘(’ token error


I'm using ubuntu 17.04 LTS alongside gcc 7.3 alognside CMake. Unfortunately, I'm getting this error:

[ 37%] Building CXX object source/server/Scripts/CMakeFiles/L5RP.dir/CarDealer/cardealer.cpp.o
/home/kkraujelis/Desktop/L5RP/ragemp/source/server/Scripts/CarDealer/cardealer.cpp:10:30: error: expected constructor, destructor, or type conversion before ‘(’ token
 CarDealer::CarOffer::CarOffer(CarDealer::CarDealer const* dealer, uint32_t price, std::string const& model, double fuelUsagePerKilo) {
                              ^
source/server/Scripts/CMakeFiles/L5RP.dir/build.make:182: recipe for target 'source/server/Scripts/CMakeFiles/L5RP.dir/CarDealer/cardealer.cpp.o' failed
make[2]: *** [source/server/Scripts/CMakeFiles/L5RP.dir/CarDealer/cardealer.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:194: recipe for target 'source/server/Scripts/CMakeFiles/L5RP.dir/all' failed
make[1]: *** [source/server/Scripts/CMakeFiles/L5RP.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Everywhere I read up about it it turned out to be basic syntax error or a lot of other things. Probably I'm blind, however everytime I checked on the code it seemed allright.

Header:

#pragma once

#define SIMEONS_CARDEALER   0

namespace L5RP {

    namespace Scripts {

        namespace CarDealer {

            class CarDealer;
            class CarDealerScript;

            class CarOffer {

                CarDealer const* dealer;
                uint32_t price;
                std::string model;
                double fuelUsagePerKilo;

            public:

                CarOffer(
                    CarDealer const* dealer,
                    uint32_t price,
                    std::string const& model,
                    double fuelUsagePerKilo
                );

                CarDealer const* getDealer() const;
                uint32_t getPrice() const;
                std::string const& getModelName() const;
                uint32_t getModel() const;
                double getFuelUsagePerKilo() const;

            };

            /*** Some other classes ***/

        }

    }

}

#include "Simeons/simeons.h"

Source:

#include "../scripts.h"

using namespace L5RP;
using namespace L5RP::Scripts;
using namespace L5RP::Scripts::Government;
using namespace L5RP::Scripts::CarDealer;
using namespace L5RP::Scripts::Character;
using namespace L5RP::Scripts::VehicleLogic;

CarDealer::CarOffer::CarOffer(CarDealer::CarDealer const* dealer, uint32_t price, std::string const& model, double fuelUsagePerKilo) {
    this->dealer = dealer;
    this->price = price;
    this->model = model;
    this->fuelUsagePerKilo = fuelUsagePerKilo;
}

Solution

  • A problem was fixed in the comment section by https://stackoverflow.com/users/6752050/s-m.

    I can't mark his comment as answer. So I will quote him:

    You use two same names CarDealer for class and namespace. If you state using the namespace then you don't need to prefix class members definitions with the namespace.