Visual Studio 2015:获取"non standard syntax, use '&' to create a pointer to member"错误

Visual Studio 2015: Getting "non standard syntax, use '&' to create a pointer to member" error

本文关键字:to create 错误 member pointer 2015 Studio 获取 non Visual syntax      更新时间:2023-10-16

当我尝试编译代码时,超级困惑。我目前正在尝试通过打印应该从文件中提取的值来测试我写的功能。

gameboard.cpp

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <fstream> 
#include "error.h"
using namespace std;
int boardDim(ifstream & inputFile, unsigned int x, unsigned int y) {
    inputFile.open; //error is thrown here
    if (!(inputFile.is_open())) {
        throw fileNotOpen;
    }
    else {
        stringstream output(inputFile.getline); //error is also thrown here
        if (output >> x) {
            if (output >> y) {
                return success;
            }
            return secBoardVarErr;
        }
        return firstBoardVarErr;
    }
    cout << x << endl;
    cout << y << endl;
}

gameboard.h

#ifndef GAMEBOARD_H
#define GAMEBOARD_H
#include <iostream>

using namespace std;
//takes in dimensions of board from file
int boardDim(ifstream &, unsigned int, unsigned int);
#endif !GAMEBOARD_H

主要功能

#include "stdafx.h"
#include "functions.h"
#include "gamepieces.h"
#include "gameboard.h"
#include "error.h"
int main(int argc, char * argv[])
{
    ifstream x("test.txt");
    int test = 0;
    cout << boardDim(x, 0, 0) << endl;  
    return success;
}

我只是在游戏板标题和源文件中测试我声明和定义的功能,因此将来将使用另一个包含的文件,但已经进行了测试,并且在我编译并运行时不会丢弃错误。

谢谢!

inputFile.open是一个函数,与 inputFile.getline相同,因此您在这里拥有的是句法错误。正确的语法是:

inputFile.open()

inputFile.getline()
相关文章: