我在编写一个链表代码进行调试的时候出现了
错误 LNK2019 无法解析的外部符号
然后我在修改后发现删掉这一句pNext = new Node[sizeof(Node)];就不会报错
这是什么原因?
以下是源代码
`
#pragma once
#include <iostream>
#include <fstream>
#include "stu_anal.h"
class Node
{
public:
Node * Add();
void Delete();
void fix();
void search();
void rank_in_Chinese();
void rank_in_Math();
void rank_in_English();
void rank_in_Total();
Node();
protected:
stu_anal st;
Node *pNext;
Node *pHead;
Node *pTail;
};
这是头文件的代码
#include "Node.h"
#include "stu_anal.h"
#include "stu_info.h"
#include "stu_score.h"
Node *Node:: Add()
{
if (pHead == NULL)
{
pNext = new Node[sizeof(Node)];
if (pHead == NULL)
{
cout << "error!" << endl;
exit(0);
}
cout << "请输入学生的信息:" << endl;
cout << "名字:";
cin >> pNext->st.name;
cout << "性别:";
cin >> pNext->st.sex;
cout << "年龄:";
cin >> pNext->st.age;
cout << "语文成绩:";
cin >> pNext->st.Chinese;
cout << "数学成绩:";
cin >> pNext->st.Math;
cout << "英语成绩:";
cin >> pNext->st.English;
pHead= pTail = pNext;
pTail->pNext = NULL;
cout << "信息已录入." << endl;
}
这是cpp文件的代码
pNext = new Node[sizeof(Node)];中间的sizeof(Node)是多大?stu_anal st;结构的大小是固定的吗?应该就是这个问题