class 的每个变量的 VS 报告错误

VS reporting error with every variable of a class

我实现了一个典型的class叫“FCB”,我编码的时候VS没有报任何问题,引用的时候能认出它的成员。 然而,当我尝试编译它时,它显示每个类型为 FCB 或 FCB* 的变量似乎无法识别。这是我的 class.

FileControlBlock.h

#pragma once

#include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std;

#include "hash.h" //a custom head file that I use to use string as hash index

//file authority
#define AUTH_ALL 0
#define AUTH_NO_DEL 1
#define AUTH_READ_ONLY 2
#define THIS_DIR 0
#define CHIL_DIR 1
#define SUC 0
#define ERR -1
#define C_ERR_DUP_NAME -1
#define C_ERR_ILL_NAME -2
#define D_ERR_LACK_AUTH -1
#define D_ERR_IS_OCCUPY -2
#define R_ERR_IS_WRITE -1
#define W_ERR_IS_OCCUPY -1

extern FCB* POS_POINTER;

class FCB
{
public:
    string name;        //file name
    char type;          //directory(.f), .exe(.e), .txt(.t)
    FCB* parent;
    int size;
    int auth;
    //only for directories
    unordered_map<unsigned int, FCB> directoryTree;

    string printRoute();            //print the route
    vector<FCB> saveDirectory();
    FCB* findFile(string fileName); 
    vector<string> printFile(char fileType);//find a certain kind of file
    FCB(string fileName = "~", int fileSize = 0);
    string printDirectory(string dirRoute = ".", int mode = THIS_DIR);
};

FCB::FCB(string fileName, int fileSize)
{
    this->name = fileName;
    int nameLen = fileName.size();
    this->type = fileName[nameLen - 1];
    this->parent = POS_POINTER;
    this->size = fileSize;
    this->auth = POS_POINTER->auth;
}

string FCB::printRoute()
{
    string route = this->name;
    return route;
}

string FCB::printDirectory(string dirRoute, int mode)
{
    string result = "";
    return result;
}

vector<string> FCB::printFile(char fileType)
{
    vector<string> result;
    return result;
}

vector<FCB> FCB::saveDirectory()
{
    vector<FCB> result;
    return result;
}

FCB* FCB::findFile(string fileName)
{
    FCB* result = NULL;
    return result;
}

FileSystem.h(未完成)

#pragma once
#include <fstream>
#include "FileControlBlock.h"

#define WRITE_HEAD 0
#define WRITE_TAIL 1
#define MAX_NAME_LEN 16

//save on the computer
const string dirLoc = "PD_OS_FS\directory.txt";

class FileSystem
{
public:
    FCB myDir;
    FileSystem();
    ~FileSystem();
    int changeRoute(string route);  
    int creatFile(string fileName);
    int deleteFile(string fileName);
    int readFile(string fileName, int pid);
    int writeFile(string fileName, string writeObj, int mode, int pid);
};

main.cpp

#include "FileSystem.h"

FCB* POS_POINTER = NULL; //位置指针

int main()
{
    return 0;
}

我的main()没有什么特别的,报错信息如下: enter image description here 抱歉,我无法将其翻译成英文。基本上,myDir 是另一个 class 类型为 FCB 的“FileSystem”的成员,但是 VS 报告 myDir 不属于 FileSystem。大部分错误都是这样的,跟class FCB有关,好像没有class.

就像@RichardCritten 的评论一样,我在FCB之前错误地声明了POS_POINTER。只需将它移到 class 之后和成员函数之前即可修复大部分 porbl