-
[RESOLVED] Unresolved external symbol
perhaps this can be a very popular error, but i´m beginner and i not used to see problems like this
Code:
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <fstream>// enable writing to and reading from files
#include <cstdlib>
#include <time.h>
using namespace std;
class Person
{
public:
//Constructor and Destructor Methods
Person(){cout<<"\n\tBuilding a Person.";};
~Person(){cout<<"\n\tDestroying a Person.";};
//Accessor Methods
string getName (){ return Name; }
string getLocation (){ return Location; }
string getAge (){ return Age; }
string getOccupation (){ return Occupation; }
void setName (string Name) { Name = Name; }
void setLocation (string Location) { Location = Location; }
void setAge (string Age) { Age = Age; }
void setOccupation (string Occupation) { Occupation = Occupation; }
private:
string Name,
Location,
Age,
Occupation;
};
//Function prototypes
void createperson();
void editperson();
void displayperson();
void saveperson();
void loadperson();
int main (int argc, char *argv[])
{
Person* cg = new Person();
char choose[10] = "";
cout<<"\n\t Personnel database 1.0\n";
//system display ("CLS");
while (choose [0] != 'q')
{
system ("CLS");
cout<<"\n\t---------------------Main Menu---------------------\n";
cout<<"\n\t| |\n";
cout<<"\n\t| (c) Create person |\n";
cout<<"\n\t| (E) edit information |\n";
cout<<"\n\t| (D) display person |\n";
cout<<"\n\t| (S) Save person |\n";
cout<<"\n\t| (L) Load person |\n";
cout<<"\n\t| (Q) quit |\n";
cout<<"\n\t| |\n";
cout<<"\n\t---------------------------------------------------\n\n\t";
cin>>choose;
//system ("CLS");
switch (choose [0])
{
//system ("CLS");
case 'c': createperson(); break;
case 'e': editperson(); break;
case 'd': displayperson(); system ("pause"); break;
case 's': saveperson(); break;
case 'l': loadperson(); break;
case 'q': cout<<"\n\tExiting main menu..."; break;
default :"\n\tInvalid input!";
}
}
system ("pause");
return 0;
}
//Function´s scope
void createperson()
{
Person* cg = new Person();
}
void editPerson()
{
Person* cg = new Person();
string TEMP;
system ("CLS");
cout<<"\n\n\t---------------------EDIT person ---------------------------";
cout<<"\n\t Name: ";
getline (cin,TEMP);
cg->setName(TEMP);
cout<<"\n\t Location ";
getline (cin,TEMP);
cg->setLocation(TEMP);
cout<<"\n\t Age: ";
getline (cin,TEMP);
cg->setAge(TEMP);
cout<<"\n\t Occupation: ";
getline (cin,TEMP);
cg->setOccupation(TEMP);
}
void displayPerson()
{
Person* cg = new Person();
system("CLS");
cout<<"\n\n\t---------------------person information----------------------";
cout<< "\n\tName: " , cg-> getName();
cout<< "\n\tOccupation:" , cg-> getLocation();
cout<< "\n\tLocation: " , cg-> getAge();
cout<< "\n\tReferences:" , cg-> getOccupation();
cout<<"\n\n\t---------------------------------------------------------------\n\n";
}
void savePerson()
{
Person* cg = new Person();
try
{
ofstream DATAFILE;
DATAFILE.open("Data1.file",ios::out);
DATAFILE <<cg->getName ()<<"\n";
DATAFILE <<cg->getLocation ()<<"\n";
DATAFILE <<cg->getAge ()<<"\n";
DATAFILE <<cg->getOccupation ()<<"\n";
DATAFILE.close(); //Prevents data from getting corrupt incase of sudden shutdown
cout<<"\n\t Success! Data was saved to file.";
}
catch (exception x)
{
cout<<"\n\t File Error! Could not SAVE PERSON.";
}
}
void loadperson()
{
Person* cg = new Person();
try
{
string TEMP;
ifstream DATAFILE;
DATAFILE.open("Data1.file",ios::in);
getline (DATAFILE,TEMP);
cg->setName (TEMP);
getline (DATAFILE,TEMP);
cg->setLocation (TEMP);
getline (DATAFILE,TEMP);
cg->setAge (TEMP);
getline (DATAFILE,TEMP);
cg->setOccupation (TEMP);
DATAFILE.close();
}
catch (exception x)
{
cout<<"\n\t File Error! Unable to load data.";
}
}
erros list:
Code:
Error 1 error LNK2019: unresolved external symbol "void __cdecl saveperson(void)" (?saveperson@@YAXXZ) referenced in function _main H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 2 error LNK2019: unresolved external symbol "void __cdecl displayperson(void)" (?displayperson@@YAXXZ) referenced in function _main H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 3 error LNK2019: unresolved external symbol "void __cdecl editperson(void)" (?editperson@@YAXXZ) referenced in function _main H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 4 error LNK1120: 3 unresolved externals H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Debug\Using_class_ in_ c++.exe 1
what i can do to fit this problem?
-
Re: Unresolved external symbol
c++ is case sensitive. ie displayperson is different to displayPerson.
Code:
void editperson();
void displayperson();
void saveperson();
...
void displayPerson()
{
You need to check that the case of your function declarations are the same as those of your function definitions and that they are also the same where the function is used.
-
Re: Unresolved external symbol
good observation!!! i ´ll take a look! thanks!
-
Re: Unresolved external symbol
the program "works well", but it no saves , no displays and no load the information that i type.
Code:
// Using_class_ in_ c++.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <fstream>// enable writing to and reading from files
#include <cstdlib>
#include <time.h>
using namespace std;
class Person
{
public:
//Constructor and Destructor Methods
Person(){cout<<"\n\tBuilding a Person.";};
~Person(){cout<<"\n\tDestroying a Person.";};
//Accessor Methods
string getName (){ return Name; }
string getLocation (){ return Location; }
string getAge (){ return Age; }
string getOccupation (){ return Occupation; }
void setName (string Name) { Name = Name; }
void setLocation (string Location) { Location = Location; }
void setAge (string Age) { Age = Age; }
void setOccupation (string Occupation) { Occupation = Occupation; }
private:
string Name,
Location,
Age,
Occupation;
};
//Function prototypes
void createperson();
void editperson();
void displayperson();
void saveperson();
void loadperson();
int main (int argc, char *argv[])
{
Person* cg = new Person();
char choose[10] = "";
cout<<"\n\t Personnel database 1.0\n";
//system display ("CLS");
while (choose [0] != 'q')
{
system ("CLS");
cout<<"\n\t---------------------Main Menu---------------------\n";
cout<<"\n\t| |\n";
cout<<"\n\t| (c) Create person |\n";
cout<<"\n\t| (E) edit information |\n";
cout<<"\n\t| (D) display person |\n";
cout<<"\n\t| (S) Save person |\n";
cout<<"\n\t| (L) Load person |\n";
cout<<"\n\t| (Q) quit |\n";
cout<<"\n\t| |\n";
cout<<"\n\t---------------------------------------------------\n\n\t";
cin>>choose;
//system ("CLS");
switch (choose [0])
{
//system ("CLS");
case 'c': createperson(); break;
case 'e': editperson(); break;
case 'd': displayperson(); system ("pause"); break;
case 's': saveperson(); break;
case 'l': loadperson(); break;
case 'q': cout<<"\n\tExiting main menu..."; break;
default :"\n\tInvalid input!";
}
}
system ("pause");
return 0;
}
//Function´s scope
void createperson()
{
Person* cg = new Person();
}
void editperson()
{
Person* cg = new Person();
string TEMP;
system ("CLS");
cout<<"\n\n\t---------------------EDIT person ---------------------------";
cout<<"\n\t Name: ";
cin.ignore();
getline (cin,TEMP);
cg->setName(TEMP);
cout<<"\n\t Location ";
getline (cin,TEMP);
cg->setLocation(TEMP);
cout<<"\n\t Age: ";
getline (cin,TEMP);
cg->setAge(TEMP);
cout<<"\n\t Occupation: ";
getline (cin,TEMP);
cg->setOccupation(TEMP);
}
void displayperson()
{
Person* cg = new Person();
system("CLS");
cout<<"\n\n\t---------------------person information----------------------";
cout<< "\n\tName: " , cg-> getName();
cout<< "\n\tOccupation:" , cg-> getLocation();
cout<< "\n\tLocation: " , cg-> getAge();
cout<< "\n\tReferences:" , cg-> getOccupation();
cout<<"\n\n\t---------------------------------------------------------------\n\n";
}
void saveperson()
{
Person* cg = new Person();
try
{
ofstream DATAFILE;
DATAFILE.open("Data1.file",ios::out);
DATAFILE <<cg->getName ()<<"\n";
DATAFILE <<cg->getLocation ()<<"\n";
DATAFILE <<cg->getAge ()<<"\n";
DATAFILE <<cg->getOccupation ()<<"\n";
DATAFILE.close(); //Prevents data from getting corrupt incase of sudden shutdown
cout<<"\n\t Success! Data was saved to file.";
}
catch (exception x)
{
cout<<"\n\t File Error! Could not SAVE PERSON.";
}
}
void loadperson()
{
Person* cg = new Person();
try
{
string TEMP;
ifstream DATAFILE;
DATAFILE.open("Data1.file",ios::in);
getline (DATAFILE,TEMP);
cg->setName (TEMP);
getline (DATAFILE,TEMP);
cg->setLocation (TEMP);
getline (DATAFILE,TEMP);
cg->setAge (TEMP);
getline (DATAFILE,TEMP);
cg->setOccupation (TEMP);
DATAFILE.close();
}
catch (exception x)
{
cout<<"\n\t File Error! Unable to load data.";
}
}
-
Re: Unresolved external symbol
Quote:
the program "works well", but it no saves , no displays and no load the information that i type.
Well it now compiles and links, but I would hardly claim that it 'works well' when it doesn't load, save or display the information!
What debugging of the program have you done? Have you traced through the program using the debugger to see where your program deviates from that which you expected?
Hint. The scope of variables defined within a function are local to that function. So if you define the same variable (say *cg) in several functions, each of these definitions refer to a different 'cg' even though they have the same name.
Also, you have memory leaks as you are using 'new' but are not deleting the memory allocated anywhere.
-
Re: Unresolved external symbol
if i retire the objects from the functions i have some problems like "cg is undefined"
how i can do to make a global object for all the functions?
-
Re: Unresolved external symbol
ok, i´ve made a global object before main method
but nothing changed
-
Re: Unresolved external symbol
i my directory was created a file Data1.file how can i read it to check if the data is saved?
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
i my directory was created a file Data1.file how can i read it to check if the data is saved?
Notepad? The VC editor?
-
Re: Unresolved external symbol
not. these txt editors only show me a empty txt.
-
Re: Unresolved external symbol
i meam that the program compiles well but not work like i would want. :D
i tried to understand what wrong is happening, but still i don´t know waht i can do. i already try to put the function save inside the function editPerson, but no progress in it.
-
Re: Unresolved external symbol
i´m instaling fileViewPro to open data1.file.
-
Re: Unresolved external symbol
See 2kaud's hint in post #5
-
Re: Unresolved external symbol
Basically, you have a couple of choices. You can either make cg a global variable, or define it in main and pass it as a parameter to each of the used functions.
If you define it at global scope then its definition would be after the definition of the class, but before main. Then in all the functions, the definition for cg would be removed.
Note that you also have a problem with your class
Code:
void setName (string Name) { Name = Name; }
This doesn't do what you think it does. You need either to have
Code:
void setName (string Name1) { Name = Name1; }
or
Code:
void setName (string Name) { this->Name = Name; }
It's usually not a good idea to have the name of parameters the same as class members.
You also need to delete the memory allocated in the createperson function or you have a memory leak.
-
Re: Unresolved external symbol
fileview pro is not for open this kind of file. :(
but the question is not this. the most imoprtant is make the program works welll!!
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
not. these txt editors only show me a empty txt.
That's because you are not setting the class members properly! See my comment in post #14 regarding the class problem
-
Re: Unresolved external symbol
i already tried it but the wrong form:
this.Name instead this->Name
i change according you told me and i´m compiling the program now.
-
Re: Unresolved external symbol
this is my update code
Code:
// Using_class_ in_ c++.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
class Person
{
public:
//Constructor and Destructor Methods
Person(){cout<<"\n\tBuilding a Person.";};
~Person(){cout<<"\n\tDestroying a Person.";};
//Accessor Methods
string getName (){ return Name; }
string getLocation (){ return Location; }
string getAge (){ return Age; }
string getOccupation (){ return Occupation; }
void setName (string Name) { this->Name = Name; }
void setLocation (string Location) { this->Location = Location; }
void setAge (string Age) { this->Age = Age; }
void setOccupation (string Occupation) { this->Occupation = Occupation; }
private:
string Name,
Location,
Age,
Occupation;
};
//Function prototypes
void createPerson();
void editPerson();
void displayPerson();
void savePerson();
void loadPerson();
Person* cg = new Person();
int main (int argc, char *argv[])
{
char choose[10] = "";
cout<<"\n\t Personnel database 1.0\n";
//system display ("CLS");
while (choose [0] != 'q')
{
system ("CLS");
cout<<"\n\t---------------------Main Menu---------------------\n";
cout<<"\n\t| |\n";
cout<<"\n\t| (c) Create person |\n";
cout<<"\n\t| (e) edit information |\n";
cout<<"\n\t| (d) display person |\n";
cout<<"\n\t| (s) Save person |\n";
cout<<"\n\t| (l) Load person |\n";
cout<<"\n\t| (q) quit |\n";
cout<<"\n\t| |\n";
cout<<"\n\t---------------------------------------------------\n\n\t";
cin>>choose;
//system ("CLS");
switch (choose [0])
{
//system ("CLS");
case 'c': createPerson(); break;
case 'e': editPerson(); break;
case 'd': displayPerson(); system ("pause"); break;
case 's': savePerson(); break;
case 'l': loadPerson(); break;
case 'q': cout<<"\n\tExiting main menu..."; break;
default :"\n\tInvalid input!";
}
}
system ("pause");
return 0;
}
//Function´s scope
void createPerson()
{
editPerson();
}
void editPerson()
{
string TEMP;
system ("CLS");
cout<<"\n\n\t---------------------EDIT person ---------------------------";
cout<<"\n\t Name: ";
cin.ignore();
getline (cin,TEMP);
cg->setName(TEMP);
cout<<"\n\t Location ";
getline (cin,TEMP);
cg->setLocation(TEMP);
cout<<"\n\t Age: ";
getline (cin,TEMP);
cg->setAge(TEMP);
cout<<"\n\t Occupation: ";
getline (cin,TEMP);
cg->setOccupation(TEMP);
}
void displayPerson()
{
system("CLS");
cout<<"\n\n\t---------------------person information----------------------";
cout<< "\n\tName: " , cg-> getName();
cout<< "\n\tLocation:" , cg-> getLocation();
cout<< "\n\tAge: " , cg-> getAge();
cout<< "\n\tOccupation:" , cg-> getOccupation();
cout<<"\n\n\t---------------------------------------------------------------\n\n";
}
void savePerson()
{
try
{
ofstream DATAFILE;
DATAFILE.open("Data1.file",ios::out);
DATAFILE <<cg->getName ()<<"\n";
DATAFILE <<cg->getLocation ()<<"\n";
DATAFILE <<cg->getAge ()<<"\n";
DATAFILE <<cg->getOccupation ()<<"\n";
DATAFILE.close(); //Prevents data from getting corrupt incase of sudden shutdown
cout<<"\n\t Success! Data was saved to file.";
}
catch (exception x)
{
cout<<"\n\t File Error! Could not SAVE PERSON.";
}
}
void loadPerson()
{
try
{
string TEMP;
ifstream DATAFILE;
DATAFILE.open("Data1.file",ios::in);
getline (DATAFILE,TEMP);
cg->setName (TEMP);
getline (DATAFILE,TEMP);
cg->setLocation (TEMP);
getline (DATAFILE,TEMP);
cg->setAge (TEMP);
getline (DATAFILE,TEMP);
cg->setOccupation (TEMP);
DATAFILE.close();
}
catch (exception x)
{
cout<<"\n\t File Error! Unable to load data.";
}
}
-
Re: Unresolved external symbol
have a nice evening, tomorrow i´ll see this problem again.
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
this is my update code
Code:
//Accessor Methods
string getName const (){ return Name; }
string getLocation const (){ return Location; }
string getAge const (){ return Age; }
string getOccupation const (){ return Occupation; }
Functions that do not change the class internals should be defined as const.
Code:
void setName (const string& Name) { this->Name = Name; }
void setLocation (const string & Location) { this->Location = Location; }
void setAge (const string & Age) { this->Age = Age; }
void setOccupation (const string & Occupation) { this->Occupation = Occupation; }
Objects such as std::string should be passed by reference or const reference, not by value.
What is the reason for dynamically allocating here?
Code:
Person* cg = new Person();
Why not just do this:
Regards,
Paul McKenzie
-
Re: Unresolved external symbol
i broke my code in two parts:
headers:
Code:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include "Person.h"
#include <iostream>
#include <string>
#include <fstream>// enable writing to and reading from files
#include <cstdlib>
#include <time.h>
// TODO: reference additional headers your program requires here
Person.h:
Code:
#ifndef PERSON_H
#define PERSON_H
class Person
{
public:
//Constructor and Destructor Method
Person(){cout<<"\n\tBuilding a Person.";};
~Person(){cout<<"\n\tDestroying a Person.";};
//Accessor Methods
string getName ()const { return Name; }
string getLocation ()const { return Location; }
string getAge ()const{ return Age; }
string getOccupation ()const{ return Occupation; }
void setName (const string& Name) { this->Name = Name; }
void setLocation (const string& Location) { this->Location = Location; }
void setAge (const string& Age) { this->Age = Age; }
void setOccupation (const string& Occupation) { this->Occupation = Occupation; }
void createPerson();
void editPerson();
void displayPerson();
void savePerson();
void loadPerson();
private:
string Name,
Location,
Age,
Occupation;
};
# endif
void Person::createPerson()
{
editPerson();
}
void Person::editPerson()
{
string TEMP;
system ("CLS");
cout<<"\n\n\t---------------------EDIT person ---------------------------";
cout<<"\n\t Name: ";
cin.ignore();
getline (cin,TEMP);
setName(TEMP);
cout<<"\n\t Location ";
getline (cin,TEMP);
setLocation(TEMP);
cout<<"\n\t Age: ";
getline (cin,TEMP);
setAge(TEMP);
cout<<"\n\t Occupation: ";
getline (cin,TEMP);
setOccupation(TEMP);
}
void Person::displayPerson()
{
system("CLS");
cout<<"\n\n\t---------------------person information----------------------";
cout<< "\n\tName: " , getName();
cout<< "\n\tLocation:" , getLocation();
cout<< "\n\tAge: " , getAge();
cout<< "\n\tOccupation:" , getOccupation();
cout<<"\n\n\t---------------------------------------------------------------\n\n";
}
void Person::savePerson()
{
try
{
ofstream DATAFILE;
DATAFILE.open("Data1.file",ios::out);
DATAFILE <<getName ()<<"\n";
DATAFILE <<getLocation ()<<"\n";
DATAFILE <<getAge ()<<"\n";
DATAFILE <<getOccupation ()<<"\n";
DATAFILE.close(); //Prevents data from getting corrupt incase of sudden shutdown
cout<<"\n\t Success! Data was saved to file.";
}
catch (exception x)
{
cout<<"\n\t File Error! Could not SAVE PERSON.";
}
}
void Person::loadPerson()
{
try
{
string TEMP;
ifstream DATAFILE;
DATAFILE.open("Data1.file",ios::in);
getline (DATAFILE,TEMP);
setName (TEMP);
getline (DATAFILE,TEMP);
setLocation (TEMP);
getline (DATAFILE,TEMP);
setAge (TEMP);
getline (DATAFILE,TEMP);
setOccupation (TEMP);
DATAFILE.close();
}
catch (exception x)
{
cout<<"\n\t File Error! Unable to load data.";
}
}
Using_class_in_c++.cpp:
Code:
// Using_class_ in_ c++.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
int main (int argc, char *argv[])
{
Person cg;
char choose[10] = "";
cout<<"\n\t Personnel database 1.0\n";
//system display ("CLS");
//Loop
while (choose [0] != 'q')
{
system ("CLS");
cout<<"\n\t---------------------Main Menu---------------------\n";
cout<<"\n\t| |\n";
cout<<"\n\t| (c) Create person |\n";
cout<<"\n\t| (e) edit information |\n";
cout<<"\n\t| (d) display person |\n";
cout<<"\n\t| (s) Save person |\n";
cout<<"\n\t| (l) Load person |\n";
cout<<"\n\t| (q) quit |\n";
cout<<"\n\t| |\n";
cout<<"\n\t---------------------------------------------------\n\n\t";
cin>>choose;
//system ("CLS");
switch (choose [0])
{
//system ("CLS");
case 'c': cg.createPerson(); break;
case 'e': cg.editPerson(); break;
case 'd': cg.displayPerson(); system ("pause"); break;
case 's': cg.savePerson(); break;
case 'l': cg.loadPerson(); break;
case 'q': cout<<"\n\tExiting main menu..."; break;
default :"\n\tInvalid input!";
}
}
system ("pause");
return 0;
}
-
Re: Unresolved external symbol
Code:
Error 1 error C2146: syntax error : missing ';' before identifier 'getName' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 3 error C2143: syntax error : missing ';' before 'const' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 6 error C2059: syntax error : ')' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 7 error C2334: unexpected token(s) preceding '{'; skipping apparent function body h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 8 error C2146: syntax error : missing ';' before identifier 'getLocation' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 10 error C2143: syntax error : missing ';' before 'const' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 13 error C2059: syntax error : ')' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 14 error C2334: unexpected token(s) preceding '{'; skipping apparent function body h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 15 error C2146: syntax error : missing ';' before identifier 'getAge' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 16 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 17 error C2143: syntax error : missing ';' before 'const' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 18 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 19 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 20 error C2059: syntax error : ')' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 21 error C2334: unexpected token(s) preceding '{'; skipping apparent function body h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 22 error C2146: syntax error : missing ';' before identifier 'getOccupation' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 23 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 24 error C2143: syntax error : missing ';' before 'const' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 25 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 26 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 27 error C2059: syntax error : ')' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 28 error C2334: unexpected token(s) preceding '{'; skipping apparent function body h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 29 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 22
Error 30 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 22
Error 31 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 23
Error 32 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 23
Error 33 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 24
Error 34 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 24
Error 35 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 25
Error 36 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 25
Error 37 error C2146: syntax error : missing ';' before identifier 'Name' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 36
Error 38 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 36
Error 39 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 36
Error 40 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 37
Error 41 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 38
Error 42 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 39
Error 43 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 12
Error 44 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 13
Error 45 error C2039: 'Name' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 22
Error 46 error C2039: 'Location' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 23
Error 47 error C2039: 'Age' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 24
Error 48 error C2039: 'Occupation' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 25
Error 49 error C2065: 'string' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 56
Error 50 error C2146: syntax error : missing ';' before identifier 'TEMP' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 56
Error 51 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 56
Error 52 error C3861: 'system': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 57
Error 53 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 58
Error 54 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 60
Error 55 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 61
Error 56 error C2228: left of '.ignore' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 61
Error 57 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 62
Error 58 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 62
Error 59 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 62
Error 60 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 63
Error 61 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 65
Error 62 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 66
Error 63 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 66
Error 64 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 66
Error 65 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 67
Error 66 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 69
Error 67 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 70
Error 68 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 70
Error 69 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 70
Error 70 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 71
Error 71 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 73
Error 72 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 74
Error 73 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 74
Error 74 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 74
Error 75 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 75
Error 76 error C3861: 'system': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 82
Error 77 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 83
Error 78 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 84
Error 79 error C3861: 'getName': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 84
Error 80 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 85
Error 81 error C3861: 'getLocation': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 85
Error 82 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 86
Error 83 error C3861: 'getAge': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 86
Error 84 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 87
Error 85 error C3861: 'getOccupation': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 87
Error 86 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 88
Error 87 error C2065: 'ofstream' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 96
Error 88 error C2146: syntax error : missing ';' before identifier 'DATAFILE' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 96
Error 89 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 96
Error 90 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 91 error C2228: left of '.open' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 92 error C2653: 'ios' : is not a class or namespace name h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 93 error C2065: 'out' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 94 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 99
Error 95 error C3861: 'getName': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 99
Error 96 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 100
Error 97 error C3861: 'getLocation': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 100
Error 98 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 101
Error 99 error C3861: 'getAge': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 101
Error 100 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 102
Error 101 error C3861: 'getOccupation': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 102
Error 102 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 104
Error 103 error C2228: left of '.close' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 104
Error 104 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 105
Error 105 error C2061: syntax error : identifier 'exception' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 107
Error 106 error C2310: catch handlers must specify one type h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 107
Error 107 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 109
Error 108 error C2317: 'try' block starting on line '95' has no catch handlers h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 111
Error 109 error C2065: 'string' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 118
Error 110 error C2146: syntax error : missing ';' before identifier 'TEMP' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 118
Error 111 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 118
Error 112 error C2065: 'ifstream' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 119
Error 113 error C2146: syntax error : missing ';' before identifier 'DATAFILE' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 119
Error 114 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 119
Error 115 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 116 error C2228: left of '.open' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 117 error C2653: 'ios' : is not a class or namespace name h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 118 error C2065: 'in' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 119 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 121
Error 120 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 121
Error 121 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 121
Error 122 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 123
Error 123 error C1003: error count exceeds 100; stopping compilation h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 123
124 IntelliSense: expected a ';' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
125 IntelliSense: class "Person" has no member "createPerson" h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 46
126 IntelliSense: identifier "getLocation" is undefined h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 100
127 IntelliSense: identifier "getAge" is undefined h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 101
128 IntelliSense: identifier "getOccupation" is undefined h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 102
129 IntelliSense: identifier "setName" is undefined h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 123
130 IntelliSense: identifier "setLocation" is undefined h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 126
131 IntelliSense: identifier "setAge" is undefined h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 129
132 IntelliSense: identifier "setOccupation" is undefined h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 132
133 IntelliSense: class "Person" has no member "createPerson" h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\using_class_ in_ c++.cpp 40
-
Re: Unresolved external symbol
before break my code this not happened, but for now the out put show this errors, what i´m doing wrong?
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
before break my code this not happened, but for now the out put show this errors, what i´m doing wrong?
I had a typo in my post:
Code:
string getName () const { return Name; }
string getLocation () const { return Location; }
string getAge () const { return Age; }
string getOccupation () const { return Occupation; }
That is the corrected code.
Also, you didn't answer why you are dynamically allocating memory to create a Person. Why introduce a potential memory leak when you don't have to? Your code now has a memory leak using "new Person()", since you never called delete cg;. But there is no need if you just did this:
Code:
int main (int argc, char *argv[])
{
Person cg;
Then you use
instead of
C++ is not Java or C# or some other language where to create an object, you must use "new". Use "new" when you have no choice but to use it. Otherwise, you open up your code to unnecessary memory leaks if the memory is not handled properly.
With the correction above, there is now no need to call delete (which you forgot to do anyway).
Regards,
Paul McKenzie
-
Re: Unresolved external symbol
i make the modifications (check it on my previous post) according you told me, and now the erros is only in Person.h
Code:
Error 1 error C2146: syntax error : missing ';' before identifier 'getName' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Warning 4 warning C4183: 'getName': missing return type; assumed to be a member function returning 'int' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 5 error C2146: syntax error : missing ';' before identifier 'getLocation' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Warning 8 warning C4183: 'getLocation': missing return type; assumed to be a member function returning 'int' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 9 error C2146: syntax error : missing ';' before identifier 'getAge' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 10 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Warning 12 warning C4183: 'getAge': missing return type; assumed to be a member function returning 'int' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 13 error C2146: syntax error : missing ';' before identifier 'getOccupation' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 14 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 15 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Warning 16 warning C4183: 'getOccupation': missing return type; assumed to be a member function returning 'int' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 17 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 22
Error 18 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 22
Error 19 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 23
Error 20 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 23
Error 21 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 24
Error 22 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 24
Error 23 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 25
Error 24 error C2143: syntax error : missing ',' before '&' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 25
Error 25 error C2146: syntax error : missing ';' before identifier 'Name' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 36
Error 26 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 36
Error 27 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 36
Error 28 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 37
Error 29 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 38
Error 30 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 39
Error 31 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 12
Error 32 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 13
Error 33 error C2065: 'Name' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 17
Error 34 error C2065: 'Location' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 18
Error 35 error C2065: 'Age' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 19
Error 36 error C2065: 'Occupation' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 20
Error 37 error C2039: 'Name' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 22
Error 38 error C2039: 'Location' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 23
Error 39 error C2039: 'Age' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 24
Error 40 error C2039: 'Occupation' : is not a member of 'Person' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 25
Error 41 error C2065: 'string' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 56
Error 42 error C2146: syntax error : missing ';' before identifier 'TEMP' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 56
Error 43 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 56
Error 44 error C3861: 'system': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 57
Error 45 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 58
Error 46 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 60
Error 47 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 61
Error 48 error C2228: left of '.ignore' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 61
Error 49 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 62
Error 50 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 62
Error 51 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 62
Error 52 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 63
Error 53 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 65
Error 54 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 66
Error 55 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 66
Error 56 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 66
Error 57 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 67
Error 58 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 69
Error 59 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 70
Error 60 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 70
Error 61 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 70
Error 62 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 71
Error 63 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 73
Error 64 error C2065: 'cin' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 74
Error 65 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 74
Error 66 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 74
Error 67 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 75
Error 68 error C3861: 'system': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 82
Error 69 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 83
Error 70 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 84
Error 71 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 85
Error 72 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 86
Error 73 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 87
Error 74 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 88
Error 75 error C2065: 'ofstream' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 96
Error 76 error C2146: syntax error : missing ';' before identifier 'DATAFILE' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 96
Error 77 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 96
Error 78 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 79 error C2228: left of '.open' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 80 error C2653: 'ios' : is not a class or namespace name h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 81 error C2065: 'out' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 97
Error 82 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 99
Error 83 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 100
Error 84 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 101
Error 85 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 102
Error 86 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 104
Error 87 error C2228: left of '.close' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 104
Error 88 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 105
Error 89 error C2061: syntax error : identifier 'exception' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 107
Error 90 error C2310: catch handlers must specify one type h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 107
Error 91 error C2065: 'cout' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 109
Error 92 error C2317: 'try' block starting on line '95' has no catch handlers h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 111
Error 93 error C2065: 'string' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 118
Error 94 error C2146: syntax error : missing ';' before identifier 'TEMP' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 118
Error 95 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 118
Error 96 error C2065: 'ifstream' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 119
Error 97 error C2146: syntax error : missing ';' before identifier 'DATAFILE' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 119
Error 98 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 119
Error 99 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 100 error C2228: left of '.open' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 101 error C2653: 'ios' : is not a class or namespace name h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 102 error C2065: 'in' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 120
Error 103 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 121
Error 104 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 121
Error 105 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 121
Error 106 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 123
Error 107 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 124
Error 108 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 124
Error 109 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 124
Error 110 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 126
Error 111 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 127
Error 112 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 127
Error 113 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 127
Error 114 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 129
Error 115 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 130
Error 116 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 130
Error 117 error C3861: 'getline': identifier not found h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 130
Error 118 error C2065: 'TEMP' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 132
Error 119 error C2065: 'DATAFILE' : undeclared identifier h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 133
Error 120 error C2228: left of '.close' must have class/struct/union h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 133
Error 121 error C2061: syntax error : identifier 'exception' h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 135
Error 122 error C2310: catch handlers must specify one type h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 135
Error 123 error C1003: error count exceeds 100; stopping compilation h:\cry_dev\programming\c++\using_class_ in_ c++\using_class_ in_ c++\person.h 135
-
Re: Unresolved external symbol
what it does means?
c++ does not support default-int error
-
Re: Unresolved external symbol
-
Re: Unresolved external symbol
In your stdafx.h, move #include "Person.h" to end of the #includes. Your Person.h file uses cout, string etc which haven't yet been defined.
-
Re: Unresolved external symbol
i forget to put namespace std, then i fix the error with 'cout´s'. i also should to put stdafx.h in Person.h? or not?
-
Re: Unresolved external symbol
okay, also complete the erros is ess then before
Code:
Error 1 error LNK2005: "public: void __thiscall Person::createPerson(void)" (?createPerson@Person@@QAEXXZ) already defined in stdafx.obj H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 2 error LNK2005: "public: void __thiscall Person::editPerson(void)" (?editPerson@Person@@QAEXXZ) already defined in stdafx.obj H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 3 error LNK2005: "public: void __thiscall Person::displayPerson(void)" (?displayPerson@Person@@QAEXXZ) already defined in stdafx.obj H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 4 error LNK2005: "public: void __thiscall Person::savePerson(void)" (?savePerson@Person@@QAEXXZ) already defined in stdafx.obj H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 5 error LNK2005: "public: void __thiscall Person::loadPerson(void)" (?loadPerson@Person@@QAEXXZ) already defined in stdafx.obj H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Using_class_ in_ c++\Using_class_ in_ c++.obj
Error 6 error LNK1169: one or more multiply defined symbols found H:\Cry_Dev\Programming\C++\Using_class_ in_ c++\Debug\Using_class_ in_ c++.exe 1
-
Re: Unresolved external symbol
i can´t understand this message
this is the central problem
'one or more multiply defined symbols found'
-
Re: Unresolved external symbol
the problem now is:
one or more multiply defined symbols found!
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
i forget to put namespace std, then i fix the error with 'cout´s'. i also should to put stdafx.h in Person.h? or not?
stdafx.h should be the first #include in your .cpp files.
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
the problem now is:
one or more multiply defined symbols found!
Calm down. You've posted that three times in five minutes. You'll likely get help, but it's not usually going to be instant.
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
i forget to put namespace std,
Where did you place the "using namespace std"? Hopefully it is not in the header file Person.h.
Second, your Person.h is wrong. The only thing in there is supposed to be the class definition and any functions that are inline with the class -- nothing else.
Code:
#ifndef PERSON_H
#define PERSON_H
#include <string>
class Person
{
public:
Person();
~Person();
//Accessor Methods
std::string getName () const { return Name; }
std::string getLocation ()const { return Location; }
std::string getAge () const { return Age; }
std::string getOccupation () const { return Occupation; }
void setName (const std::string& Name) { this->Name = Name; }
void setLocation (const std::string& Location) { this->Location = Location; }
void setAge (const std::string& Age) { this->Age = Age; }
void setOccupation (const std::string& Occupation) { this->Occupation = Occupation; }
void createPerson();
void editPerson();
void displayPerson();
void savePerson();
void loadPerson();
private:
std::string Name,
Location,
Age,
Occupation;
};
# endif
That is all that should be in there, nothing else. Then you create a module, Person.cpp that includes this header, and in that file you implement the functions that aren't implemented in the class definition itself.
Also note that there is no "using namespace std" in the Person.h header file -- this has been discussed many times on this board and other places as to why it is not a good idea to place using clauses in headers. Instead, you see std:: appended to the string type.
Also, what you see in the header are all the headers that are necessary for Person.h to be able to live by itself. That's why <string> is included, because you are using std::string in the class. Your original header file did not #include <string> which was wrong.
Regards,
Paul McKenzie
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
the problem now is:
one or more multiply defined symbols found!
Read my post and fix Person.h. It should not have class functions outside the class in that header. Those functions go into a separate, compilable, C++ module called preferably, Person.cpp.
Regards,
Paul McKenzie
-
Re: Unresolved external symbol
-
Re: Unresolved external symbol
code updated:
Person.H
Code:
#ifndef PERSON_H
#define PERSON_H
using namespace std;
class Person
{
public:
//Constructor and Destructor Method:
Person();
~Person();
//funstions:
void createPerson();
void editPerson();
void displayPerson();
void savePerson();
void loadPerson();
//Accessor Methods:
string getName ()const { return Name; }
string getLocation ()const { return Location; }
string getAge ()const{ return Age; }
string getOccupation ()const{ return Occupation; }
void setName (const string& Name) { this->Name = Name; }
void setLocation (const string& Location) { this->Location = Location; }
void setAge (const string& Age) { this->Age = Age; }
void setOccupation (const string& Occupation) { this->Occupation = Occupation; }
private:
//private variables:
string Name,
Location,
Age,
Occupation;
};
# endif
Cpp file
Code:
// Using_class_ in_ c++.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
//scope functions
Person::Person () {cout<<"\n\tBuilding a Person.";}
Person::~Person(){cout<<"\n\tDestroying a Person.";}
void Person::createPerson()
{
Person::editPerson();
}
void Person::editPerson()
{
string TEMP;
system ("CLS");
cout<<"\n\n\t---------------------EDIT person ---------------------------";
cout<<"\n\t Name: ";
cin.ignore();
getline (cin,TEMP);
setName(TEMP);
cout<<"\n\t Location ";
getline (cin,TEMP);
setLocation(TEMP);
cout<<"\n\t Age: ";
getline (cin,TEMP);
setAge(TEMP);
cout<<"\n\t Occupation: ";
getline (cin,TEMP);
setOccupation(TEMP);
}
void Person::displayPerson()
{
system("CLS");
cout<<"\n\n\t---------------------person information----------------------";
cout<< "\n\tName: " , getName();
cout<< "\n\tLocation:" , getLocation();
cout<< "\n\tAge: " , getAge();
cout<< "\n\tOccupation:" , getOccupation();
cout<<"\n\n\t---------------------------------------------------------------\n\n";
}
void Person::savePerson()
{
try
{
ofstream DATAFILE;
DATAFILE.open("Data1.file",ios::out);
DATAFILE <<getName ()<<"\n";
DATAFILE <<getLocation ()<<"\n";
DATAFILE <<getAge ()<<"\n";
DATAFILE <<getOccupation ()<<"\n";
DATAFILE.close(); //Prevents data from getting corrupt incase of sudden shutdown
cout<<"\n\t Success! Data was saved to file.";
}
catch (exception x)
{
cout<<"\n\t File Error! Could not SAVE PERSON.";
}
}
void Person::loadPerson()
{
try
{
string TEMP;
ifstream DATAFILE;
DATAFILE.open("Data1.file",ios::in);
getline (DATAFILE,TEMP);
setName (TEMP);
getline (DATAFILE,TEMP);
setLocation (TEMP);
getline (DATAFILE,TEMP);
setAge (TEMP);
getline (DATAFILE,TEMP);
setOccupation (TEMP);
DATAFILE.close();
}
catch (exception x)
{
cout<<"\n\t File Error! Unable to load data.";
}
}
//end funstions scope
//main method
int main (int argc, char *argv[])
{
Person cg;
char choose[10] = "";
cout<<"\n\t Personnel database 1.0\n";
//system display ("CLS");
//Loop
while (choose [0] != 'q')
{
system ("CLS");
cout<<"\n\t---------------------Main Menu---------------------\n";
cout<<"\n\t| |\n";
cout<<"\n\t| (c) Create person |\n";
cout<<"\n\t| (e) edit information |\n";
cout<<"\n\t| (d) display person |\n";
cout<<"\n\t| (s) Save person |\n";
cout<<"\n\t| (l) Load person |\n";
cout<<"\n\t| (q) quit |\n";
cout<<"\n\t| |\n";
cout<<"\n\t---------------------------------------------------\n\n\t";
cin>>choose;
//system ("CLS");
switch (choose [0])
{
//system ("CLS");
case 'c': cg.createPerson(); break;
case 'e': cg.editPerson(); break;
case 'd': cg.displayPerson(); system ("pause"); break;
case 's': cg.savePerson(); break;
case 'l': cg.loadPerson(); break;
case 'q': cout<<"\n\tExiting main menu..."; break;
default :"\n\tInvalid input!";
}
}
system ("pause");
return 0;
}
-
Re: Unresolved external symbol
no errors on output
but i think the logic is wrong because the program is not saving data, and neither displaying.
:|
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
code updated:
Person.H
Code:
#ifndef PERSON_H
#define PERSON_H
using namespace std;
class Person
{
...
};
# endif
Did't you read what Paul wrote?
Quote:
Originally Posted by
Paul McKenzie
Where did you place the "using namespace std"? Hopefully it is not in the header file Person.h.
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
no errors on output
but i think the logic is wrong because the program is not saving data, and neither displaying.
So why didn't you debug it to see what, where and why goes wrong?
-
Re: Unresolved external symbol
You have a problem with displayPerson
Code:
cout<< "\n\tName: " , getName();
This is actually two statements separated by a comma. (The comma operator). First the cout is executed (which shows Name). Then the getName() function is executed with its return value not used. You need
Code:
cout << "\n\tName: " << getName();
It is not normal practice to put the class function definitions in the header file. These usually go in a .cpp file. The .h header file normally just contains the class definition. Also it is not advised to put 'using' in a header file. If a header file uses string, cout etc then they are normally referenced via their full scoped name (std::cout, std::string etc). The 'using' statement would go in the .cpp file if required.
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
no errors on output but i think the logic is wrong because the program is not saving data, and neither displaying.
See my post #42 re displaying. My copy of the program saves and loads data OK. 'type data1.file' at the command prompt to show the current data.
-
Re: Unresolved external symbol
if i don´t put namespace in Person.h it not works because the strings types. what the best way to do it?
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
if i don´t put namespace in Person.h it not works because the strings types. what the best way to do it?
See last para of my post #42. In the header file you use std::string, std::cout etc etc etc.
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
if i don´t put namespace in Person.h it not works because the strings types. what the best way to do it?
Put it in .cpp file(s)
-
Re: Unresolved external symbol
finally we make this program works well!! thanks for every one that spend time to help me.
the program works fine with namespace in Person.h, but if i try
std::string getName ()const { return Name; }
the error continues
-
Re: Unresolved external symbol
obs.: namespace are in cpp and .h
-
Re: Unresolved external symbol
Quote:
Originally Posted by
crisdeveloper
obs.: namespace are in cpp and .h
Take the "using namespace std" out of the .h file. Use the namespace within the .cpp file only.
Regards,
Paul McKenzie
-
Re: Unresolved external symbol
when i retire the namespace from .h it no works!