C++ --> 错误:'conf'之前的预期')'

C++ --> error: expected ')' before 'conf'

本文关键字:conf 错误 C++ gt      更新时间:2023-10-16

我不明白错误在哪里...它给了我:错误:当我构建时,在"conf"之前预期")"...

这是通用.cpp文件。

#include <stdio.h>
#include "generic.h"
#include <string>
#include <iostream>

Generic(dynamic_reconfigure::Config conf ) //Costruttore
{
   this->conf = conf;
}
int Generic::addInt(std::string name, int value)
{
   dynamic_reconfigure::IntParameter int_param;
   std::cout << "Insert an integer value of " << name << ":n";
   std::cin >> value;
   std::cout << "Setting " << name << "nn";
   std::cout << "Matched value: " << value << "nn";
   int_param.name=name;
   int_param.value=value;
   this->conf.ints.push_back(int_param);
return value;
}

这里有 generic.h 文件:

 #ifndef GENERIC_H_INCLUDED
 #define GENERIC_H_INCLUDED
 #include <string>
 #include <dynamic_reconfigure/IntParameter.h>
 #include <dynamic_reconfigure/Config.h>
 class Generic{
    dynamic_reconfigure::Config conf;
    public:
    Generic(dynamic_reconfigure::Config conf ); //Costruttore
    int addInt(std::string name, int value);
};
 #endif // GENERIC_H_INCLUDED

我还尝试将dynamic_reconfigure::Config conf作为公共的,但没有。你可以帮我吗?

构造函数是类的成员,当您在类定义之外定义成员时,您需要指定类名,然后指定成员名,例如

Generic::Generic(dynamic_reconfigure::Config conf ) //Costruttore
^^^^^^^  ^^^^^^^
 class    member

你的构造函数定义在你的代码中Generic,你需要Generic::Generic

你需要用类规范正确定义构造函数:

Generic::Generic(dynamic_reconfigure::Config conf)
^^^^^^^

首先,通过粘贴编译器的输出来帮助我们帮助您 - 或者至少粘贴有关您遇到的特定错误的行(包括导致此错误的代码行)。

其次,不建议在头文件中#include <string>或任何其他包含。 请参阅 https://stackoverflow.com/a/553869/1778249 了解何时有用。