C++ 成员函数错误:在'.'令牌之前需要','或'...'
c++ member function error: expected a ',' or '...' before '.' token
所以我在Visual Studio 2015中写了一个程序,并尝试将其转移到Ubuntu。除了问题,我还没有遇到任何问题。
我有一个名为" InputData"的类,带有一个构造函数,该类别需要两个字符串将其放入ifstream中:
class InputData {
( ... )
public:
InputData(string filea.c_str(), string fileb.c_str());
}
,在我的构造函数中,我有
InputData::InputData(string filea.c_str(), string fileb.c_str())
{
ifstream instream;
instream.open(filea.c_str());
( ... )
最后,在我的主要功能中,我有
InputData x ("firstfile.csv", "secondfile.csv");
但是,当我尝试将它们链接在一起并编译时,我会收到错误:
expected a ',' or '...' before '.' token
InputData(string filea.c_str(), string fileb.c_str());
^
我以前从未见过这种错误,我不知道有什么问题。谁能帮忙?
(另外,我正在使用.cstr(),因为我的编译器由于某种原因与C 11不兼容或不更新到C 11。如果我不使用CSTR,我会遇到另一个错误。>
编译器错误是因为在构造函数声明中,每个参数必须具有指定类型和该类型的变量 name ,就像任何C 函数一样。但是变量名不能包括'.'
字符,因此错误:filea.c_str()
不是有效的变量名称。这是一个函数调用。
,您的构造函数应该像InputData(string filea, string fileb)
。
编译为C++11
使用GCC编译器标志-std=c++11
。
相关文章:
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- LINUX 操作系统上的错误:令牌之前预期的构造函数、析构函数或类型转换'('?
- 错误 c++ 在令牌之前'('预期的构造函数、析构函数或类型转换
- 是什么导致了构造函数之后的这些"意外令牌"错误?
- 错误 - 此处不允许在 { 令牌之前使用函数定义
- C++ 成员函数错误:在'.'令牌之前需要','或'...'
- 错误:令牌之前的预期构造函数、析构函数或类型转换'*'
- 函数概率:令牌之前'['预期的非限定 id
- C++模板错误:'<'令牌之前的预期构造函数、析构函数或类型转换
- 将字符串拆分为令牌-不包含操作系统特定的函数
- C++:函数返回静态库中的字符串给出错误:在令牌之前':'预期的"="、""、";"、'asm'或'__attribute__'
- 错误:'<'令牌之前的预期构造函数、析构函数、类型转换
- 错误:令牌之前的预期','或';' '{' - 函数
- 令牌之前的预期构造函数、析构函数或类型转换'*'
- 野牛解析器:创建一个返回令牌的函数
- C++ 错误:令牌之前的预期构造函数、析构函数或类型转换'*'
- C++错误:"令牌之前的预期构造函数、析构函数或类型转换'<'
- 函数定义中'*'令牌之前的预期构造函数、析构函数或类型转换
- 如何使"strtok function"一次使用多个令牌字符串? 函数指针会解决这个问题吗?
- C++令牌之前'('预期的构造函数、析构函数或类型转换