预期在“(”令牌错误之前的构造函数,析构函数或类型转换

时间:2018-06-26 00:52:41

标签: c++ ubuntu gcc ubuntu-17.04

我正在将ubuntu 17.04 LTS与gcc 7.3 alognside CMake一起使用。不幸的是,我收到此错误:

[ 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

在所有我读过的地方,发现它都是基本语法错误或许多其他事情。可能我是盲人,但是每次我检查代码时都没事。

标题:

#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"

来源:

#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;
}

2 个答案:

答案 0 :(得分:1)

https://stackoverflow.com/users/6752050/s-m在评论部分中解决了一个问题。

我无法将他的评论标记为答案。所以我要引用他:

  

您对类和名称空间使用两个相同的名称CarDealer。如果您声明使用名称空间,则无需在类成员定义之前添加名称空间。

答案 1 :(得分:0)

实现功能时,必须完全限定包括名称空间在内的类类型。

通常,您只需将定义用适当的命名空间包围起来,如下所示:

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

更好的是,您将在适当的时候在初始化列表中初始化您的成员。因此您的代码如下所示:

namespace L5RP 
{
    namespace Scripts 
    {
        namespace CarDealer 
        {
            CarOffer::CarOffer(CarDealer const* dealer, uint32_t price, std::string const& model, double fuelUsagePerKilo) 
                : dealer(dealer)
                , price(price)
                , model(model)
                , fuelUsagePerKilo(fuelUsagePerKilo)
            {
            }
        }
    }
}