我刚刚从C#切换到C++我在C++中编写了一个链接列表代码在win32控制台应用程序中运行它并在构建时遇到非常奇怪的错误
我在评论中指出了3个错误,其余的我不能打字,它太多了.
using namespace std;
class float_list
{
struct node
{
double data;
struct node *next;
};
node *head;
public:
float_list(void)
{
head = nullptr;
};
void appendNode(double);
};
//void float_list::appendNode(float num)
//{
//
//}
void float_list::appendNode(double num)
{
node *newNode;
node *ptr; //here i am getting this Error error C3872:
//'0xa0': this character is not allowed in an identifier ,
// how ever I changed its name again and again.
newNode = new node;
newNode->data = num; // here …Run Code Online (Sandbox Code Playgroud) 我在几个树代码中看到,树类的一个函数同时具有*和&与节点,例如在BST中插入一个节点,函数是这样的
insertnode(node * &t,string value)
{
t = new node; t-> val = value
// code to find right place in BST
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么我们通常引用指针,特别是这种情况.还请提及是否还有其他任何情况,谢谢
而不是发布另一个问题.有人也可以指出对象类的使用吗?我的意思是使用对象类的实例它是否分配了所有子类的所有内存?即int float等.