繁体   English   中英

即使定义了“使用未声明的标识符'IntQueue'”

[英]“Use of undeclared identifier 'IntQueue' ” even though it is defined

我收到一条错误消息,说在vscode中使用了未声明的标识符'IntQueue',但我无法弄清楚出了什么问题。

我尝试重命名文件,但仍然无法正常工作。 我创建了一个单独的头文件,该文件定义了类,并将头文件包含在已定义所有构造函数的主cpp文件中。 但是我找不到解决问题的方法。

//This is the IntQueue.h header file
#ifdef _IntQueue_
#define _IntQueue_
#include<iostream>
#include<fstream>
using namespace std;

class IntQueue {
    int* numbers;
    int size;
    int front;
    int back;
public:
    IntQueue (unsigned int n);
    IntQueue();
    ~IntQueue();
    int getSize() {return size;}
    int getFront() {return front;}
    int getBack() {return back;}
    void incSize();
    void pop();
    int frontNumber();
    void push(int i);
    void reverse();
};

#endif

//This is the IntQueue.cpp file (incomplete)

#include "IntQueue.h"

IntQueue::IntQueue (unsigned int n) {
    size = n;
    numbers = new int[size];
    front = 0;
    back = 0;
}

IntQueue::IntQueue() {
    size = 100;
    front = 0;
    back = 0
    numbers = new int [size];
}

你需要改变

#ifdef _IntQueue_

#ifndef _IntQueue_

.cpp文件#include.h文件时,尚未声明_IntQueue_ ,因此#ifdef跳过.h文件的全部内容,因此编译器对IntQueueIntQueue

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM