正在尝试引用已删除的函数(VS2013)
Attempting to reference a deleted function (VS2013)
我正在尝试用SDL编写一个跳棋游戏。当我编译代码时,我会得到以下错误:
std::basic_ifstream>::basic_iffstream(conststd::basic_ifstream>&)':试图引用已删除的函数
根据我在网上找到的信息,这意味着编译出于某种原因删除了我的构造函数,现在它再也找不到了。(如果你问我,组织不好)为什么会这样?
Board.h:
#include <fstream>
class Board
{
public:
SDL_Surface * boardSurface;
int boardArray[8][8];
private:
std::ifstream boardFile;
SDL_Surface * blackPiece;
SDL_Surface * whitePiece;
SDL_Surface * darkSquare;
SDL_Surface * lightSquare;
public:
Board(char filename[], SDL_PixelFormat * format);
private:
void loadFile(char filename[]);
void makeSurface();
void debugPrint();
void debugBlit();
};
Board.cpp:
#include <SDL.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include "board.h"
#include "loaders.h"
Board::Board(char filename[], SDL_PixelFormat * format)
{
//inits images
loaders imageLoader;
blackPiece = imageLoader.load_image("images/blackPiece.png", format);
whitePiece = imageLoader.load_image("images/whitePiece.png", format);
darkSquare = imageLoader.load_image("images/darkSquare.png", format);
lightSquare = imageLoader.load_image("images/lightSquare.png", format);
boardSurface = SDL_CreateRGBSurface(0, 780, 480, 8, 0, 0, 0, 0);
loadFile(filename);
debugPrint();
debugBlit();
}
void Board::loadFile(char filename[])
{
boardFile.open(filename);
char currentLine[9] = {};
for (int line = 0; line <= 7; line++)
{
boardFile.getline(currentLine, 9);
for (int square = 0; square <= 7; square++)
{
int currentSquare = (int)currentLine[square] - '0';
boardArray[line][square] = currentSquare;
}
}
}
void Board::makeSurface()
{
}
void Board::debugPrint()
{
for (int line = 0; line <= 7; line++)
{
for (int square = 0; square <= 7; square++)
{
std::cout << boardArray[line][square];
}
std::cout << std::endl;
}
}
void Board::debugBlit()
{
for (int y = 0; y <= 4; y++)
{
if (SDL_BlitSurface(blackPiece, NULL, boardSurface, NULL) != 0)
{
std::cout << SDL_GetError();
}
}
}
发生此错误的原因是您有一个std::ifstream
数据成员,并且您可能正在尝试将Board
复制到某个位置,或者有一些代码需要可以访问复制构造函数。
std::ifstream boardFile;
Board
编译器提供的复制构造函数试图复制流,但该流不可复制。因此,您必须提供自己的复制构造函数来做一些巧妙的事情,或者删除需要Board
复制构造函数的代码。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 当构造函数在VS2013中调用自身时会发生什么?
- 在VS2013与VS2017的printf函数中使用宏
- 正在尝试引用已删除的函数(VS2013)
- C++VS2013:覆盖默认构造函数不起作用
- VS2013无法根据模板参数指定具有通用引用和返回类型的函数模板
- 继承 VS2013 中的构造函数
- 如何让 VS2013 停止生成对整数类型之间强制转换的__dtol3、__dtoui3和其他函数的调用
- 为什么 c++ 编译器 (VS2013) 选择了错误的函数
- VS2013 has_nothrow_constructor与受保护的构造函数
- VS2013 RC中函数模板的过载解决方案
- 是否允许类模板的函数签名模板参数中使用未展开的参数包?(可能的VS2013错误)
- 错误:对的调用没有匹配的函数调用-使用VS2013编译
- 在VS2013中使用initializer_list对函数的调用不明确
- 为什么VS2013将函数调用编译成两个指令而不是一个
- 带有成员函数的VS2013 std::函数
- 编译器在VC12 (VS2013)中生成移动构造函数行为
- VS2013:将迭代器传递给接受指针的函数(将VS2010迁移到VS2013)