Hi there
I'm trying to implement a link list which stores the city name (though you will see this commented out as I need to resolve the issue of not being able to use string and needing to use a primitive data type instead during the declaration), longitude, latitude and of course a pointer to the next node in the chain. I am new to the Visual C++ environment and my brain is somewhat scrambled after coding for several straight hours today so I wondered if anyone could help resolve the 2 errors I am getting (ignore the #include syntax as I had to change them to avoid the browser interpreting html!):
1>U08221.obj : error LNK2028: unresolved token (0A000298) "public: __thiscall Locations::Locations(void)" (??0Locations@@$$FQAE@XZ) referenced in function "int __clrcall main(cli::array^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z) 1>U08221.obj : error LNK2019: unresolved external symbol "public: __thiscall Locations::Locations(void)" (??0Locations@@$$FQAE@XZ) referenced in function "int __clrcall main(cli::array^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
The code for my header file is here:
#include <string>
struct locationNode
{
//char[10] nodeCityName;
double nodeLati;
double nodeLongi;
locationNode* Next;
};
class Locations
{
private:
int size;
public:
Locations(); // constructor for the class
locationNode* Head;
int Add(locationNode* Item);
};
and here is the code for the file containing the main method:
// U08221.cpp : main project file.
#include "stdafx.h"
#include "Locations.h"
#include <iostream>
#include <string>
using namespace std;
int n = 0;
int x;
string cityNameInput;
bool acceptedInput = false;
int Locations::Add(locationNode *NewItem)
{
locationNode *Sample = new locationNode;
Sample = NewItem;
Sample->Next = Head;
Head = Sample;
return size++;
}
void CorrectCase(string name) // Correct upper and lower case letters of input
{
x = name.size();
int firstLetVal = name[0], letVal;
n = 1; // variable for name index from second letter onwards
if((name[0] >90) && (name[0] < 123)) // First letter is lower case
{
firstLetVal = firstLetVal - 32; // Capitalise first letter
name[0] = firstLetVal;
}
while(n <= x - 1)
{
if((name[n] >= 65) && (name[n] <= 90))
{
letVal = name[n] + 32;
name[n] = letVal;
}
n++;
}
cityNameInput = name;
}
void nameValidation(string name)
{
n = 0; // start from first letter
x = name.size();
while(!acceptedInput)
{
if((name[n] >= 65) && (name[n] <= 122)) // is in the range of letters
{
while(n <= x - 1)
{
while((name[n] >=91) && (name[n] <=97)) // ERROR!!
{
cout << "Please enter a valid city name" << endl;
cin >> name;
}
n++;
}
}
else {
cout << "Please enter a valid city name" << endl;
cin >> name;
}
if(n <= x - 1)
{
acceptedInput = true;
}
}
cityNameInput = name;
}
int main(array<System::String ^> ^args)
{
cout << "Enter a city name" << endl;
cin >> cityNameInput;
nameValidation(cityNameInput); // check is made up of valid characters
CorrectCase(cityNameInput); // corrects name to standard format of capitalised first letter, and lower case subsequent letters
cout << cityNameInput;
cin >> cityNameInput;
Locations::Locations();
Locations *Parts = new Locations();
locationNode *Part;
Part = new locationNode;
//Part->nodeCityName = "London";
Part->nodeLati = 87;
Part->nodeLongi = 80;
Parts->Add(Part);
}
I am familiar with the concepts but somewhat inexperienced with OOP so am making some silly errors that you can never find when you've stared at something too long. Any help you can offer will be appreciated!
Thanks