Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this error: expected ')' before '&' token?

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.

 /** @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.

like image 307
woodenToaster Avatar asked Feb 18 '23 13:02

woodenToaster


2 Answers

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 Translator(std::ifstream& fin) {
    ...
}

If this is a constructor, you need to provide its qualified name:

Translator::Translator(std::ifstream& fin) {
    ...
}
like image 139
Sergey Kalinichenko Avatar answered Feb 20 '23 03:02

Sergey Kalinichenko


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).

like image 31
Yuushi Avatar answered Feb 20 '23 03:02

Yuushi