开发者

why am I getting an error when I pass an ifstream&?

I'm trying to code a simple program that uses an ifstream and scanner to read a text file. For some reason I'm getting this error: "In passing argument 1 of 'bool ReadVector(std::ifstream&, Vector<double>&)'". Any idea what I've done wrong?

#include <iostream>
#include <fstream>
#include <string&g开发者_如何转开发t;
#include "scanner.h"
#include "genlib.h"
#include "simpio.h"
#include "vector.h"

// prototype
bool ReadVector(ifstream & infile, Vector<double> & vec);

// main
int main(){
    Vector<double> vec;
    ifstream infile;
    infile.open("SquareAndCubeRoots.txt");
    if (infile.fail()) Error("Opening file screwed up");
    bool foo = ReadVector(&infile, &vec); // stub
    cout << foo;
    infile.close();
    return 0;
}

// stub
bool ReadVector(ifstream & infile, Vector<double> & vec){
    return true;
}


ReadVector accepts a reference, but you are giving a pointer. Just call

bool foo = ReadVector(infile, vec);


You're trying to pass a pointer, while the argument is a reference. Remove address-of operators (ReadVector(infile, vec)).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜