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

时间:2013-11-10 20:04:25

标签: c++ compiler-errors

我不明白哪里出错... 它给了我:错误:预期')'在'conf'之前我建立......

这是generic.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 << "\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;
}

这里有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作为公共但没有。 你能救我吗?

4 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

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

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

答案 3 :(得分:-1)

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

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