簡體   English   中英

c ++標頭中的編譯器錯誤,“未在此范圍內聲明”

[英]compiler error in c++ header, “was not declared in this scope”

當我嘗試編譯我的頭文件時,編譯器告訴我“'map'未在此范圍內聲明”( public:下面的行:)。 為什么?

#pragma once
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
#include <vector>
#ifndef TILEMAP_H
#define TILEMAP_H

class TileMap{

public:
    std::vector<std::vector<sf::Vector2i>> map;
    std::ifstream file;
    TileMap(std::string name);
    sf::Sprite tiles;
    sf::Texture tileTexture;
    void update();
    void draw(sf::RenderWindow* window);



};

#endif

您應該在兩個“>”之間有一個空格,否則編譯器會將其與“>>”運算符混淆。 所以這樣做:

std::vector<std::vector<sf::Vector2i> > map;

這就是為什么如果要在另一個內部使用一個STL類型,那么輸入自定義STL類型總是一個好主意。 所以這樣做更好:

typedef std::vector<sf::Vector2i> Mytype;
std::vector<Mytype> map;

這樣你就不會因為忘記在“>”之間放置空格而得到編譯錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM