gpt4 book ai didi

c++ - 试图引用已删除的函数(VS2013)

转载 作者:行者123 更新时间:2023-11-30 01:54:46 26 4
gpt4 key购买 nike

我正在尝试用 SDL 编写跳棋游戏。当我编译我的代码时,我得到这个错误:

std::basic_ifstream>::basic_ifstream(conststd::basic_ifstream> &)' : attempting to reference a deleted function

根据我在网上找到的信息,这意味着编译出于某种原因帮助删除了我的构造函数,现在它再也找不到了。 (如果你问我,组织不好)为什么会这样?

板.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();
};

板.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 复制构造函数的代码。

关于c++ - 试图引用已删除的函数(VS2013),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21664164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com