通常、このエラーが発生した場合は、新しいプロジェクトを作成し、コードをコピーして貼り付けて修正しますが、現在は修正されていません。
出力は次のとおりです。
1>------ Build started: Project: myList, Configuration: Debug Win32 ------
1> List.cpp
1>List.obj : error LNK2019: unresolved external symbol "void __cdecl printStd(struct Student >*)" (?printStd@@YAXPAUStudent@@@Z) referenced in function _main
1>C:\Users\Talmid\Desktop\אמרי\C\myList\Debug\myList.exe : fatal error LNK1120: 1 unresolved >externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
そしてコード:
#include <stdio.h>
#include <stdlib.h>
#define SUCCESS 1
#define FAILURE 0
// A definition of some information type:
typedef struct
{
char name[20];
int id;
}Student;
// A definition of a single node
typedef struct node_s
{
Student data;
struct node_s *next;
}Node;
// a definition of "list manager":
typedef struct
{
Node *start;
int num;
}List;
List *createList();
int insertToList(List *ptrList, Student *ptrStu);
int removeFirst(List *ptrList, Student *ptrStu);
Node *getRecord(List *ptrList, int recNum);
void printList(List *ptrList);
void printRec(Node *ptrNode);
void printStd(Student *std);
void freeList(List *ptrList);
void shutDown(List *ptrList);
//Creates a new 'list manager', initializes it and returns its value;
List *createList()
{
List *ptrNewList = (List *)malloc(sizeof(List));
if(ptrNewList)
{
ptrNewList->start = NULL;
ptrNewList->num = 0;
}
return ptrNewList;
}
// free 'list manager'
void shutDown(List *pList)
{
if(pList != NULL)
free(pList);
}
// inserts one record a the head of the list
int insertToList(List *ptrList, Student *ptrStu)
{
Node *ptrNewNode = (Node *)malloc(sizeof(Node));
if(ptrNewNode)
{
ptrNewNode->data = *ptrStu;
ptrNewNode->next = ptrList->start;
ptrList->start = ptrNewNode;
ptrList->num++;
return SUCCESS;
}
return FAILURE;
}
// remooves the first node from the list
int removeFirst(List *ptrList, Student *ptrStu)
{
Node *ptrDel;
if(ptrList->start != NULL)
{
ptrDel = ptrList->start;
ptrList->start = ptrDel->next;
ptrList->num--;
*ptrStu = ptrDel->data;
free(ptrDel);
return SUCCESS;
}
return FAILURE;
}
// gets the data of the recNum node
Node *getRecord(List *ptrList, int recNum)
{
Node *ptrNode;
int nodeNum = 1;
ptrNode = ptrList->start;
while((nodeNum<recNum) && (ptrNode != NULL))
{
ptrNode = ptrNode->next;
nodeNum++;
}
return ptrNode;
}
// prints the entire list
void printList(List *ptrList)
{
Node *ptrNode;
int i;
ptrNode = ptrList->start;
i = 1;
while(ptrNode != NULL)
{
printf("%2d: ",i);
printRec(ptrNode);
ptrNode = ptrNode->next;
i++;
}
printf("\n");
}
// prints a given record
void printRec(Node *ptrNode)
{
printf("name is %10s, id is %d.\n", ptrNode->data.name, ptrNode->data.id);
}
// prints a given student
void printSt(Student *std)
{
printf("name is %10s, id is %d.\n", std->name, std->id);
}
//free all nodes (dynamic allocation)
void freeList(List *ptrList)
{
Node *ptrDel;
if(ptrList != NULL)
{
ptrDel = ptrList->start;
while(ptrDel)
{
ptrList->start = ptrDel->next;
free(ptrDel);
ptrDel = ptrList->start;
}
}
}
void main()
{
List *l1 = NULL;
Node *n1 = NULL;
Student *s1 = NULL;
int i, status;
int wantedIndexElement = 3;
Student studentsArr[] = {
{"Rina",134},
{"Tomer",22307},
{"Rotem",3732},
{"Yosef",773},
{"Anat",9998},
{"Vered",14555},
{"Malkishua",878},
{"David",6543},
{"Yigal",9870},
{"Beni",123}
};
int arrLen = sizeof(studentsArr)/sizeof(Student);
l1 = createList();
if(l1 == NULL)
{
printf("problem to allocate List (list manager)\n");
exit(1);
}
for(i=0;i<arrLen;i++)
{
status = insertToList(l1,&studentsArr[i]);
if(status == FAILURE)
{
printf("Failed to insert to the list!!!\n");
exit(1);
}
}
printList(l1);
n1 = getRecord(l1,wantedIndexElement);
if(n1 != NULL)
printRec(n1);
else
printf("No such element %d \n",wantedIndexElement);
s1 = (Student *)malloc(sizeof(Student));
if (removeFirst(l1,s1) == FAILURE)
{
printf("Failed to remove from list!!!\n");
exit(1);
}
printf("The student has been deleted:\n");
printStd(s1);
freeList(l1);
shutDown(l1);
l1 = NULL;
putchar('\n');
getchar();
}
それはあなたが本当にそれをチェックする必要がない長いコードなので、間違いはありません..コンソールでさえそう言った:D
では、このエラーの意味は何ですか?なぜそれを取得するのですか?どうすれば修正できますか?それは私を存在すらしないexeファイルに導きます。
ありがとう