Vengant

I hope someone is able to help me with this. I am trying to create a double linked list program with several navigation options, using managed code. I am recieving this error when compiling and I'm unsure why. I'll post some code,

Code Snippet

void addtToStart(student ^start)

{

printHeader();

student ^newstudent;

try

{

if (start==nullptr) //empty

{

student ^newstudent = gcnew student; //creates a node if there isn't one allready

newstudent->prev = nullptr;

newstudent->next = nullptr;

newstudent->id = idcounter;

idcounter++;

initData(newstudent); //set values to default

start = newstudent;

}

else

{

student ^newstudent = gcnew student; //creates a node at the beginning

newstudent->prev = nullptr; //fixes the pointers

newstudent->next = start;

newstudent->id = idcounter;

idcounter++;

initData(newstudent); //set values to default

start = newstudent;

}

}

catch (...)

{

Console::WriteLine("I'm sorry, there has been an error");

return;

}

getData(newstudent);

}

this particular function is supposed to add an node at the start, the struc looks like this

ref struct student

{

String^ firstName;

String ^lastName;

String^ course;

int id, cost, grade;

char letterGrade;

student ^next;

student ^prev;

};

the specific error(including all the command line *** for main) is:

DoubleLinkedList.obj : error LNK2028: unresolved token (0A000018) "void __clrcall addToStart(struct student ^)" ( addToStart@@$$FYMXP$AAUstudent@@@Z) referenced in function "int __clrcall main(cli::array<class System:Tongue Tiedtring ^ >^)" ( main@@$$HYMHP$01AP$AAVString@System@@@Z)

and

DoubleLinkedList.obj : error LNK2019: unresolved external symbol "void __clrcall addToStart(struct student ^)" ( addToStart@@$$FYMXP$AAUstudent@@@Z) referenced in function "int __clrcall main(cli::array<class System:Tongue Tiedtring ^ >^)" ( main@@$$HYMHP$01AP$AAVString@System@@@Z)




Re: Visual C++ Express Edition "error LNK2028: unresolved token", cannot find help resource

Andreas Johansson

Are you using addToStart before it is declared in the source file

You can fix this with a forward declaration at the top of the class.

Code Snippet

void addToStart(student ^start);






Re: Visual C++ Express Edition "error LNK2028: unresolved token", cannot find help resource

Vengant

Yes actually, I had originally declared student ^start as a global, but it did not work in managed mode. So I declared it inside main and then passed it as a parameter. I have all of my functions protyped at the beginning of the code.






Re: Visual C++ Express Edition "error LNK2028: unresolved token", cannot find help resource

Vengant

Sorry to shamelessy bump my own thread but I am still stumped. I haven't been able to find any resources and I'm wondering if anyone has been able to figure this one out.




Re: Visual C++ Express Edition "error LNK2028: unresolved token", cannot find help resource

Andreas Johansson

No bumping please, it is in the unanswered list and we pay attention to it. It is also in my list of thread with a big unanswered icon in front of it. Smile

I would need to see more code to help you further, either post it here if it is not too much or you could also send me a mail with the files. My mail is in my profile.






Re: Visual C++ Express Edition "error LNK2028: unresolved token", cannot find help resource

Vengant

the code is not too much. I'll post it here. I thought I had it figured out because I was playing with compiler options and in slrTongue Tiedafe it said that try/catch/throw was an unmanaged function call. so I commented it out and it still gave the linker error.

Code Snippet

// DoubleLinkedList.cpp : main project file.

#include "stdafx.h"

using namespace System;

ref struct student

{

String^ firstName;

String^ lastName;

String^ course;

int id, cost, grade;

char letterGrade;

student ^next;

student ^prev;

};

int idcounter = 1;

void printHeader();

void addToStart(student ^start);

void printList(student ^start);

//void deleteAll();

bool quit();

int getNumber();

void initData(student ^newstudent);

void getData(student ^newstudent);

char calcGrade(int x);

int main(array<System::String ^> ^args)

{

student ^start;

start = nullptr;

int choice;

while(1)

{

printHeader();

Console::WriteLine("1. Add a record at the beginning of the list");

//Console::WriteLine("2. Add a record at the end of the list");

//Console::WriteLine("3. Delete a record at the end of the list");

//Console::WriteLine("4. Insert a student before another student");

//Console::WriteLine("5. Insert a student after another student");

//Console::WriteLine("6. Delete a record before a specific record");

//Console::WriteLine("7. Delete a record after a specific record");

Console::WriteLine("8. Print the list of all student records");

//Console::WriteLine("9. Print the list of all students, backwards");

Console::WriteLine("0. Delete all records, then quit");

choice = getNumber(); // returns number, or -1 if exception

switch (choice)

{

case 1: { addToStart(start); break; }

case 8: { printList(start); break; }

case 0:

{

//deleteAll();

//if (quit) { return 0; }

//else { break; }

return 0;

}

default:

{

Console::Write("You entered an invalid option, press any key to continue...");

Console::ReadKey();

break;

}

}

}

}

void addtToStart(student ^start)

{

printHeader();

student ^newstudent;

//try

//{

if (start==nullptr) //empty

{

student ^newstudent = gcnew student; //creates a node if there isn't one allready

newstudent->prev = nullptr;

newstudent->next = nullptr;

newstudent->id = idcounter;

idcounter++;

initData(newstudent); //set values to default

start = newstudent;

}

else

{

student ^newstudent = gcnew student; //creates a node at the beginning

newstudent->prev = nullptr; //fixes the pointers

newstudent->next = start;

newstudent->id = idcounter;

idcounter++;

initData(newstudent); //set values to default

start = newstudent;

}

//}

//catch (...)

//{

// Console::WriteLine("I'm sorry, there has been an error");

// return;

//}

getData(newstudent);

return;

}

void printList(student ^start)

{

student ^current;

current = start;

printHeader();

while(current->next != nullptr)

{

Console::WriteLine("Student ID: {0}", current->id);

Console::WriteLine("First Name: {0}", current->firstName);

Console::WriteLine("Last Name: {0}", current->lastName);

Console::WriteLine("Course: {0}", current->course);

Console::WriteLine("Cost: {0}", current->cost);

Console::WriteLine("Grade: {0}", current->grade);

current=current->next;

}

Console::ReadKey();

return;

}

void printHeader()

{

Console::Clear();

Console::ForegroundColor = ConsoleColor::Red;

Console::WriteLine("**********************************************");

Console::Write("* ");

Console::ResetColor();

Console::Write("Welcome to the Student Information Database");

Console::ForegroundColor = ConsoleColor::Red;

Console::WriteLine(" *");

Console::WriteLine("**********************************************");

Console::ResetColor();

Console::SetCursorPosition(0, Console::CursorTop + 2);

return;

}

int getNumber()

{

int num;

try

{

num = Convert::ToInt16(Console::ReadLine());

}

catch (...)

{

return -1;

}

return num;

}

void initData(student ^newstudent)

{

newstudent->firstName = "Empty";

newstudent->lastName = "Emtpy";

newstudent->course = "Empty";

newstudent->cost = 0;

newstudent->grade = 100;

newstudent->letterGrade = calcGrade(newstudent->grade);

return;

}

void getData(student ^newstudent)

{

int choice;

while(1)

{

printHeader();

Console::WriteLine("Record created succesfully, please enter data now");

Console::WriteLine("Please Choose one of the following options");

Console::WriteLine("1. First Name:");

Console::WriteLine("2. Last Name:");

Console::WriteLine("3. Course:");

Console::WriteLine("4. Cost:");

Console::WriteLine("5. Grade:");

Console::WriteLine("0. Return to Main Menu:");

Console::WriteLine("What element of the current record would you like to change ");

Console::SetCursorPosition(0,18);

Console::WriteLine("The record currently contains");

Console::WriteLine("First Name: {0}", newstudent->firstName);

Console::WriteLine("Last Name: {0}", newstudent->lastName);

Console::WriteLine("Course: {0}", newstudent->course);

Console::WriteLine("Cost: {0}", newstudent->cost);

Console::WriteLine("Grade: {0}", newstudent->grade);

Console::SetCursorPosition(0,6);

choice = getNumber();

switch (choice)

{

case 1: // first name

{

printHeader();

Console::Write("Enter the student's First Name:");

newstudent->firstName = Console::ReadLine();

break;

}

case 2: // last name

{

printHeader();

Console::Write("Enter the student's Last Name:");

newstudent->lastName = Console::ReadLine();

break;

}

case 3: // course

{

printHeader();

Console::Write("Enter the student's course:");

newstudent->course = Console::ReadLine();

break;

}

case 4: // cost

{

while(1)

{

printHeader();

Console::Write("Enter the cost of {0}:", newstudent->course);

newstudent->cost = getNumber(); // returns -1 if exception is found

if (newstudent->cost == -1)

{

Console::WriteLine("That is an invalid cost, press any key to try again");

Console::ReadKey();

}

else { break; }

}

break;

}

case 5: // percentage grade

{

while(1)

{

printHeader();

Console::Write("Enter the grade percentage out of 100:");

newstudent->grade = getNumber(); // returns -1 if exception is found

if (newstudent->cost == -1)

{

Console::WriteLine("That is an invalid grade, press any key to try again");

Console::ReadKey();

}

else { break; }

}

break;

}

case 0: { return; }

default:

{

Console::Write("You entered an invalid option, press any key to continue...");

Console::ReadKey();

break;

}

}

}

}

char calcGrade(int x)

{

if (x >= 90){ return 'A'; }

if (x < 90 && x >= 80) { return 'B'; }

if (x < 80 && x >= 70) { return 'C'; }

if (x < 70 && x >= 60) { return 'D'; }

else { return 'F'; }

}

I'm sorry, I don't know how to preserve formatting when copying code blocks. Hopefully this is readable.






Re: Visual C++ Express Edition "error LNK2028: unresolved token", cannot find help resource

Vengant

I feel a bit embarrased by this addmission but here goes. The entire linking error and unresolved token is due to a stupid typo. I protoyped the function as addToStart(), and called it with the same syntax.. yet I defined it as addtToStart()... note the extra t.

So... thanks for the reply but I figured this one out. Of course, not I have other problems but I'll figure them out.