Put it in .cpp file(s)
Printable View
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
obs.: namespace are in cpp and .h
when i retire the namespace from .h it no works!
That is because your program is still not set up properly.
There should be no "using namespace std" in the Person.h header file. If there is, remove it and fix the problem. Otherwise you have in front of you a badly assembled program, regardless of whether it runs or not, and you haven't really learned how to properly put together a real C++ program.
First, what is not working? Does the program compile? If not, what are the errors? Post the current Person.h header file.
Regards,
Paul McKenzie
the program works well, saves, edit, and display the data.
but i would like to know how i can optmize my code.
But programming is much more than seeing a program "work". What about the way you've put together the program? Things like this:
Why is there a try/catch here? What function in the "try" throws an exception? If none of those lines throws an exception, then try/catch is not necessary.Code: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.";
}
Second, even if you wanted to write a catch block, the exception can be caught by reference, not by value.
Before you can even consider optimizing anything, you need to know and use the C++ language much better than your current level. For example, there wasn't one const or usage of references anywhere in the original code you posted. Usage of const and references is important in optimizing C++ code.Quote:
but i would like to know how i can optmize my code.
Last, we have no idea what your current code looks like.
Regards,
Paul McKenzie
in the reality i took this code from a forum to study c++, maybe it seems not a good idea but i´ve learned a lot is these 2 days trying to solve the code from another person.
give me a good reference of a c++ book, and thanks for your advice.
you can close this topic, because i´m newbie in this forum and i don´t know how i can do it.
You might like to look at these web sites
http://www.learncpp.com/
http://www.cplusplus.com/doc/tutorial/
There are many, many c++ books available. For an intro to c++, I like the Ivor Horton books. Then there are the Deitel books which are often recommended. There are the Sams Teach Yourself c++ range of books which some find useful from which to learn. Note that there is a new ANSI c++ standard - c++11 - which only books published very recently will cover. The previous ANSI standard from 1998 was covered properly in books from about 2002. If you buy older second hand c++ books look at their #include statements. If they have #include <iostream.h> then the book doesn't cover ansi c++. If it has #include <iostream> then it probably does.
Hope this helps.:)
A thread isn't closed. But you can mark it as resolved.
See http://forums.codeguru.com/faq.php?f..._item_resolved
thanks for these links, both are very helpfull for me!
i found more errors in this project for example: the data was overwriting the last information typed, but i fitted this errors.
i´ve made a lot of modifications in this project before i leave it, if someone want to check i uploaded it in this link:
http://www.4shared.com/rar/cE-7u1wF/...ss__in__c.html