C++ 为什么我会收到此错误:在 '&' 标记之前预期为 ')'?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14804176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why am I getting this error: expected ')' before '&' token?
提问by woodenToaster
I assume it has something to do with the #includes, but this is my first time trying to use them so I'm a little lost. I just wondered if anyone could tell immediately if there was an obvious mistake.
我认为它与#includes 有关,但这是我第一次尝试使用它们,所以我有点迷茫。我只是想知道是否有人可以立即判断是否有明显的错误。
/** @file Translator.cpp */
#include <fstream>
#include "Translator.h"
#include <vector>
Translator(std::ifstream& fin) //error appears on this line
{
T1(fin);
T1.createTable(fin);
T2(fin);
T2.createTable(fin));
string temp;
while(!fin.eof())
{
fin >> temp;
message.push_back(temp);
}
}
Thanks for your time.
谢谢你的时间。
回答by dasblinkenlight
It is hard to answer this question exactly without seeing the header, but if this is a function, you need to add a return type of void
to the definition of your function:
如果不看标题,很难准确回答这个问题,但如果这是一个函数,则需要void
在函数定义中添加一个返回类型:
void Translator(std::ifstream& fin) {
...
}
If this is a constructor, you need to provide its qualified name:
如果这是一个构造函数,则需要提供其限定名称:
Translator::Translator(std::ifstream& fin) {
...
}
回答by Yuushi
Without the declaration of Translator
it's a bit hard to say, but if it's meant to be a constructor, then it should be Translator::Translator(std::ifstream& fin)
. If it's meant to be a method, then it should have a return type specified, so something like void Translator(std::ifstream& fin)
.
没有Translator
它的声明有点难说,但如果它是一个构造函数,那么它应该是Translator::Translator(std::ifstream& fin)
. 如果它是一个方法,那么它应该指定一个返回类型,比如void Translator(std::ifstream& fin)
.