0

I don't understand where is error... It gives me: error: expected ')' before 'conf' when I build...

This is generic.cpp file.

#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 << "\n\n";
   std::cout << "Matched value: " << value << "\n\n";
   int_param.name=name;
   int_param.value=value;
   this->conf.ints.push_back(int_param);

return value;
}

Here there is generic.h file:

 #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

I also tried to put dynamic_reconfigure::Config conf as public but nothing. Can you help me?

4

4 回答 4

5

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

Generic::Generic(dynamic_reconfigure::Config conf ) //Costruttore
^^^^^^^  ^^^^^^^
 class    member
于 2013-11-10T20:06:28.700 回答
1

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

于 2013-11-10T20:06:47.997 回答
1

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

Generic::Generic(dynamic_reconfigure::Config conf)
^^^^^^^
于 2013-11-10T20:06:53.533 回答
-1

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

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

于 2013-11-10T20:11:40.063 回答