IntelliSense PCH 警告

huangapple go评论58阅读模式
英文:

IntelliSense PCH warning

问题

这是我遇到问题的头文件代码。我有两个错误:

  1. PCH警告:头文件不在文件范围内。未生成 IntelliSense PCH 文件。

  2. LNK1168 无法打开文件以进行写入。

我尝试过添加#pragma一次,并将#endif移到底部,但都没有效果。我是编程初学者,对混乱的代码表示抱歉。如果有人能帮助我解决这个问题,我会很感激。

英文:

This is the header file code that I am having issues with. I have these two errors:

PCH WARNING: header stop not at file scope. An IntelliSense PCH file was not generated.

LNK1168 cannot open file for writing.

I've tried adding #pragma once and moving the #endif to the bottom, yet nothing works. I am a beginner at coding so excuse me for the messy code. I Would appreciate if someone could help me with this issue.

#pragma once
#ifndef BST_H
#define BST_H
#include <vector>
#include <string>
template <class T>
class BST
{
private:
class Node
{
public:
T element;
Node* left;
Node* right;
Node(T element);
~Node() {};
};
Node* root;
void ToGraphvizHelper(std::string& listOfNodes, std::string& listOfConnections, Node* toWorkWith, size_t& uniqueID);
public:
BST();
~BST();
void insert(T element);
void remove(T element);
bool find(T element);
std::vector<T> inOrderWalk();
std::vector<T> preOrderWalk();
std::vector<T> postOrderWalk();
int getTreeHeight();
T getMin();
T getMax();
std::string ToGraphviz();
};
template <class T>
std::string BST<T>::ToGraphviz() // Member function of the AVLTree class
{
std::string toReturn = "";
if (this->root) // root is a pointer to the root node of the tree
{
std::string listOfNodes;
std::string listOfConnections = std::string("\t\"Root\" -> ") + std::to_string(0) + std::string(";\n");
toReturn += std::string("digraph {\n");
size_t id = 0;
ToGraphvizHelper(listOfNodes, listOfConnections, root, id);
toReturn += listOfNodes;
toReturn += listOfConnections;
toReturn += std::string("}");
}
return toReturn;
}
template <class T>
void BST<T>::ToGraphvizHelper(std::string& listOfNodes, std::string& listOfConnections, Node* toWorkWith, size_t& uniqueID) // Member function of the AVLTree class
{
size_t myID = uniqueID;
listOfNodes += std::string("\t") + std::to_string(myID) + std::string(" [label=\"") + std::to_string(toWorkWith->element) + std::string("\"];\n");
if (toWorkWith->left)
{
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID + 1) + std::string(" [color=blue];\n");
ToGraphvizHelper(listOfNodes, listOfConnections, toWorkWith->left, ++uniqueID);
}
else
{
listOfNodes += std::string("\t") + std::to_string(++uniqueID) + std::string(" [label=") + std::string("nill, style = invis];\n");
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID) + std::string(" [ style = invis];\n");
}
if (toWorkWith->right)
{
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID + 1) + std::string(" [color=red];\n");
ToGraphvizHelper(listOfNodes, listOfConnections, toWorkWith->right, ++uniqueID);
}
else
{
listOfNodes += std::string("\t") + std::to_string(++uniqueID) + std::string(" [label=") + std::string("nill, style = invis];\n");
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID) + std::string(" [ style = invis];\n");
}
}
#endif //BST_H
template<class T>
inline BST<T>::BST()
{
}
template<class T>
inline BST<T>::~BST()
{
}
template<class T>
inline void BST<T>::insert(T element)
{
if (root == nullptr)
{
root = new Node(element);
}
else
{
Node* current = root;
Node* parent = nullptr;
while (current != nullptr)
{
parent = current;
if (element == current->element)
{
return;
}
else if (element < current->element)
{
current = current->left;
}
else
{
current = current->right;
}
}
if (element < parent->element)
{
parent->left = new Node(element);
}
else
{
parent->right = new Node(element);
}
}
}
template<class T>
inline void BST<T>::remove(T element)
{
}
template<class T>
inline bool BST<T>::find(T element)
{
}
template<class T>
inline std::vector<T> BST<T>::inOrderWalk()
{
return std::vector<T>();
}
template<class T>
inline std::vector<T> BST<T>::preOrderWalk()
{
return std::vector<T>();
}
template<class T>`
inline std::vector<T> BST<T>::postOrderWalk()
{
return std::vector<T>();
}
template<class T>
inline int BST<T>::getTreeHeight()
{
return 0;
}
template<class T>
inline T BST<T>::getMin()
{
Node* current = root;
while (current->left != nullptr)
{
current = current->left;
}
return current->element;
}
template<class T>
inline T BST<T>::getMax()
{
Node* current = root;
while (current->right != nullptr)
{
current = current->right;
}
return current->element;
}
template <typename T>
BST<T>::Node::Node(T element) : element(element), left(nullptr), right(nullptr)
{
}
#pragma once
#ifndef BST_H
#define BST_H
#include <vector>
#include <string>
template <class T>
class BST
{
private:
class Node
{
public:
T element;
Node* left;
Node* right;
Node(T element);
~Node() {};
};
Node* root;
void ToGraphvizHelper(std::string& listOfNodes, std::string& listOfConnections, Node* toWorkWith, size_t& uniqueID);
public:
BST();
~BST();
void insert(T element);
void remove(T element);
bool find(T element);
std::vector<T> inOrderWalk();
std::vector<T> preOrderWalk();
std::vector<T> postOrderWalk();
int getTreeHeight();
T getMin();
T getMax();
std::string ToGraphviz();
};
template <class T>
std::string BST<T>::ToGraphviz() // Member function of the AVLTree class
{
std::string toReturn = "";
if (this->root) // root is a pointer to the root node of the tree
{
std::string listOfNodes;
std::string listOfConnections = std::string("\t\"Root\" -> ") + std::to_string(0) + std::string(";\n");
toReturn += std::string("digraph {\n");
size_t id = 0;
ToGraphvizHelper(listOfNodes, listOfConnections, root, id);
toReturn += listOfNodes;
toReturn += listOfConnections;
toReturn += std::string("}");
}
return toReturn;
}
template <class T>
void BST<T>::ToGraphvizHelper(std::string& listOfNodes, std::string& listOfConnections, Node* toWorkWith, size_t& uniqueID) // Member function of the AVLTree class
{
size_t myID = uniqueID;
listOfNodes += std::string("\t") + std::to_string(myID) + std::string(" [label=\"") + std::to_string(toWorkWith->element) + std::string("\"];\n");
if (toWorkWith->left)
{
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID + 1) + std::string(" [color=blue];\n");
ToGraphvizHelper(listOfNodes, listOfConnections, toWorkWith->left, ++uniqueID);
}
else
{
listOfNodes += std::string("\t") + std::to_string(++uniqueID) + std::string(" [label=") + std::string("nill, style = invis];\n");
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID) + std::string(" [ style = invis];\n");
}
if (toWorkWith->right)
{
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID + 1) + std::string(" [color=red];\n");
ToGraphvizHelper(listOfNodes, listOfConnections, toWorkWith->right, ++uniqueID);
}
else
{
listOfNodes += std::string("\t") + std::to_string(++uniqueID) + std::string(" [label=") + std::string("nill, style = invis];\n");
listOfConnections += std::string("\t") + std::to_string(myID) + std::string(" -> ") + std::to_string(uniqueID) + std::string(" [ style = invis];\n");
}
}
#endif //BST_H
template<class T>
inline BST<T>::BST()
{
}
template<class T>
inline BST<T>::~BST()
{
}
template<class T>
inline void BST<T>::insert(T element)
{
if (root == nullptr)
{
root = new Node(element);
}
else
{
Node* current = root;
Node* parent = nullptr;
while (current != nullptr)
{
parent = current;
if (element == current->element)
{
return;
}
else if (element < current->element)
{
current = current->left;
}
else
{
current = current->right;
}
}
if (element < parent->element)
{
parent->left = new Node(element);
}
else
{
parent->right = new Node(element);
}
}
}
template<class T>
inline void BST<T>::remove(T element)
{
}
template<class T>
inline bool BST<T>::find(T element)
{
}
template<class T>
inline std::vector<T> BST<T>::inOrderWalk()
{
return std::vector<T>();
}
template<class T>
inline std::vector<T> BST<T>::preOrderWalk()
{
return std::vector<T>();
}
template<class T>
inline std::vector<T> BST<T>::postOrderWalk()
{
return std::vector<T>();
}
template<class T>
inline int BST<T>::getTreeHeight()
{
return 0;
}
template<class T>
inline T BST<T>::getMin()
{
Node* current = root;
while (current->left != nullptr)
{
current = current->left;
}
return current->element;
}
template<class T>
inline T BST<T>::getMax()
{
Node* current = root;
while (current->right != nullptr)
{
current = current->right;
}
return current->element;
}
template <typename T>
BST<T>::Node::Node(T element) : element(element), left(nullptr), right(nullptr)
{
}

答案1

得分: 1

#endif //BST_H - 这是一个头文件的结束标记。它不在文件末尾。将其移到文件末尾。请注意,错误不会立即消失,IntelliSense不是实时工具,会在超时间隔内运行。

#pragma once 被所有重要的C++编译器支持多年,您可以安全地停止使用头文件保护,并删除 #ifndef BST_H#define BST_H#endif //BST_H

英文:

#endif //BST_H - this is a header stop. It's not at the file end. Move it to at the file end. Note, the error doesn't disappear immediately, IntelliSense is not a realtime tool and runs with timeout intervals.

#pragma once is supported by all significant C++ compilers for many years, you can safely stop using header guards and remove #ifndef BST_H, #define BST_H and #endif //BST_H.

huangapple
  • 本文由 发表于 2023年5月8日 00:24:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定