Error Message when compiling code.

When I try to compile the code below, I get " error: statement cannot resolve address of overloaded function."

What does this mean?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

#define die(msg) {cerr << msg << endl; exit(1);}
#define REWIND {fs.clear; fs.seekg(0L,ios::beg);}

using namespace std;

void lineNum(fstream &);
void wordCount(fstream &);

int main(int argc, char *argv[])
{  
    fstream fs(argv[1],ios::in);
    if(!fs.is_open()) die("Can not open file!");

    lineNum(fs);
    REWIND;
    wordCount(fs);
    fs.close();
}

void lineNum(fstream &fs)
{
    string line;
    int cnt = 0;
    for(int i = 0; getline(fs,line); i++)
    {
        cnt++;
    }
    cout <<"Number of Lines: "<< cnt <<endl;
}

void wordCount(fstream &fs)
{
    string str;
    int cnt = 0;
    for(int i = 0; fs >> str; i++)
    {
        cnt++;
    }
    cout <<"Number of Words: "<< cnt << endl;
}


in REWIND, clear is a function, it needs parenthesis.

I would also not suggest using the cpp to inline functions like that, but it should compile now.
Last edited on
THANK YOU SO MUCH Ganado!!!!! It worked!

The funny thing is that my instructor gave us that Macro, I guess he left out the () on purpose. :/

This is my first programming class, so can you please elaborate on:

"I would also not suggest using the cpp to inline functions like that".

Thanks again!

You're welcome, also by that I meant the macros that you used. It's really not a problem for now, but for more complicated things it can cause strange bugs, and be hell to debug.
http://stackoverflow.com/a/14041847

For example, for your macro REWIND to work, your fstream variable defined in main must be named fs or else it won't work, so it's not portable. There are better ways to account for things like this, but I wouldn't worry about it for now.
Last edited on
Thanks for the explanation. Now I see what your saying.
Topic archived. No new replies allowed.