[英]“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
文件的全部內容,因此編譯器對IntQueue
類IntQueue
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.