help write c++ code

#include <fstream>
using std::ifstream;

#include <map>
using std::map;

#include "tokens.h"
using std::cin;
using std::cout;
using std::cerr;
using std::endl;

int
main(int argc, char *argv[])
{
int lineNumber = 0;

Token tok;

istream *in = &cin;
ifstream file;

bool vflag = false;
bool allidsflag = false;
bool sumflag = false;

int tokCount = 0;
int stringCount = 0;
int identCount = 0;
map<TokenType,int> counts;
map<string,bool> identifiers;

for( int i=1; i<argc; i++ ) {
string arg( argv[i] );
if( arg == "-v" )
vflag = true;
else if( arg == "-allids" )
allidsflag = true;
else if( arg == "-sum" )
sumflag = true;
else if( arg[0] == '-' ) {
cerr << "INVALID FLAG " << arg << endl;
return 0;
}
else if( in != &cin ) {
cerr << "TOO MANY FILE NAMES" << endl;
return 0;
}
else {
file.open(arg);
if( file.is_open() == false ) {
cerr << "UNABLE TO OPEN " << arg << endl;
return 0;
}

in = &file;
}
}

while( (tok = getNextToken(in, &lineNumber)) != DONE && tok != ERR ) {
if( vflag )
cout << tok << endl;

++tokCount;
if( tok == SCONST ) {
stringCount++;
}
else if( tok == ID ) {
identCount++;
identifiers[ tok.GetLexeme() ] = true;
}
}

if( tok == ERR ) {
cout << "Error on line " << lineNumber << " (" << tok.GetLexeme() << ")" << endl;
return 0;
}

if( allidsflag && identifiers.size() > 0 ) {
cout << "IDENTIFIERS: ";
auto it = identifiers.begin();
cout << it->first;

for( it++; it != identifiers.end(); it++ )
cout << ", " << it->first;
cout << endl;
}

if( sumflag ) {
cout << "Total lines: " << lineNumber << endl;
cout << "Total tokens: " << tokCount << endl;
if( tokCount > 0 ) {
cout << "Total identifiers: " << identCount << endl;
cout << "Total strings: " << stringCount << endl;
}
}

return 0;
}


have error:
main.cpp:68:44: error: invalid initialization of reference of type ‘std::istream& {aka std::basic_istream<char>&}’ from expression of type ‘std::istream* {aka std::basic_istream<ch
ar>*}’
while( (tok = getNextToken(in, &lineNumber)) != DONE && tok != ERR ) {
We can see that 'in' is a pointer: istream* in;
We can't see the declaration of getNextToken(), but it probably has:
getNextToken( std::istream&, int* )

Simplified example:
1
2
3
4
5
6
7
8
9
void foo( int& x ) {
  x = 42;
}

int main() {
  int bar = 7;
  int* gaz = &bar;
  foo( gaz ); // error: cannot initialize reference from pointer
}


Syntactically, this probably is acceptable:
getNextToken( *in, &lineNumber )
Topic archived. No new replies allowed.