-
May 14th, 2013, 12:39 PM
#46
Re: Unresolved external symbol
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)
Victor Nijegorodov
-
May 14th, 2013, 12:47 PM
#47
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
-
May 14th, 2013, 12:50 PM
#48
Re: Unresolved external symbol
obs.: namespace are in cpp and .h
-
May 14th, 2013, 01:19 PM
#49
Re: Unresolved external symbol
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
-
May 14th, 2013, 01:22 PM
#50
Re: Unresolved external symbol
when i retire the namespace from .h it no works!
-
May 14th, 2013, 01:26 PM
#51
Re: Unresolved external symbol
Originally Posted by crisdeveloper
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
Last edited by Paul McKenzie; May 14th, 2013 at 01:30 PM.
-
May 14th, 2013, 01:30 PM
#52
Re: Unresolved external symbol
the program works well, saves, edit, and display the data.
but i would like to know how i can optmize my code.
-
May 14th, 2013, 01:41 PM
#53
Re: Unresolved external symbol
Originally Posted by crisdeveloper
the program works well, saves, edit, and display the data.
But programming is much more than seeing a program "work". What about the way you've put together the program? Things like this:
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.";
}
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.
Second, even if you wanted to write a catch block, the exception can be caught by reference, not by value.
but i would like to know how i can optmize my code.
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.
Last, we have no idea what your current code looks like.
Regards,
Paul McKenzie
-
May 14th, 2013, 01:47 PM
#54
Re: Unresolved external symbol
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.
-
May 14th, 2013, 01:57 PM
#55
Re: Unresolved external symbol
you can close this topic, because i´m newbie in this forum and i don´t know how i can do it.
-
May 14th, 2013, 02:06 PM
#56
Re: Unresolved external symbol
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 14th, 2013, 02:08 PM
#57
Re: Unresolved external symbol
Originally Posted by crisdeveloper
you can close this topic, because i´m newbie in this forum and i don´t know how i can do it.
A thread isn't closed. But you can mark it as resolved.
See http://forums.codeguru.com/faq.php?f..._item_resolved
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 14th, 2013, 03:15 PM
#58
Re: [RESOLVED] Unresolved external symbol
thanks for these links, both are very helpfull for me!
-
May 15th, 2013, 10:15 AM
#59
Re: [RESOLVED] Unresolved external symbol
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|