开发者

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

开发者 https://www.devze.com 2023-04-02 20:26 出处:网络
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&, Ve

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

精彩评论

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