当我尝试编译我的代码时,对于抛出错误的问题感到非常困惑。我目前正在试图通过打印出应该从文件中提取的值来测试我编写的函数。Visual Studio 2015:获取“非标准语法,使用'和'创建成员指针”错误
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;
}
我只测试函数I声明并在游戏键盘头文件和源定义文件,所以其他包含的文件将在未来使用,但已经过测试,不会丢失编译和运行时出现错误。
谢谢!
'inputFile.open; //在这里抛出错误 - 这不是你在'C++'中调用函数的方式。圆括号在哪里?奇怪的是,你在这里省略了括号,但是没有在'is_open()'函数之后放弃它。 – PaulMcKenzie
@paulMcKenzie,谢谢!我仍然在学习这门语言! – Harrison