|
|
..... but no matter what I do, I either get errors, memory printing to the scrren, or my program crashes. |
http://www.cplusplus.com/reference/string/string/ |
m_fName
. This makes it easier for naming things - m_fName = fName;
const
wherever you can:
|
|
|
|
|
|
|
|
Based on your post here, I'm assuming PERSON is the same struct. http://www.cplusplus.com/forum/beginner/93761/ Your use of string and copy at lines 5 and 6 is flawed. copy() will copy characters out of string, but str is empty. The second argument to copy() is a length argument, not a source string. http://www.cplusplus.com/reference/string/string/copy/ Your strcpy's at 7 and 8 should be okay, but as others have said use strings, not char arrays. |
There is a convention that member variables can start with m_ as in m_fName. This makes it easier for naming things - m_fName = fName; It is preferable to initialise variables with default values, as you have done with head & tail, as opposed to to assignment. ( I learnt this recently myself.) This is because the default constructor initialises variables first, then they get reassigned by your constructor straight away, so using the initialiser list is more efficient. And to always use const wherever you can: 1 2 3 4 5 6 7 8 addressBook::addressBook(const std::string fName, const std::string lName, const std::string address) : head(0), tail(-1), m_fName(fName), m_lName(lName), m_address(address) { //other code here - if any } This code is just an example starting with your code, I am not sure of what the entire structure of your class is, or whether you might change it after seeing my comments above. Hope all goes well. |
I assume then that I should also follow suit in my header as well? |
|
|
You should always put a default clause in a switch to catch bad input - just like an else in an if statement. Just thinking the code in the switch cases should be part of member functions, which the switch would call. That way everything is encapsulated in the class |
|
|
http://www.cplusplus.com/doc/ |
So this would then take the vector that ties into the struct, create m_fName, and then tie it into th fName from the struct itself, which would then get added to the addPErson function? If so, how do I tie that into addPerson? Right now I have it as addPerson(tmp);. Would I instead just do it as addPerson(people?); |
Thanks for the help by the way, this is actually starting to make some sense now. |
Oh, and if I've already included std::string; up at the top, do I still need it in the constructor? |
using namespace std; |
|
|
std::
before any other STL thing, that doesn't appear very often, like std::find
say.std::
everywhere and don't have any using statements at all.using namespace std; |
std::distance
?Error 1 error C2059: syntax error : '.' c:\users\cj\documents\visual studio 2012\projects\address\address\addressbook.cpp 36 1 address 6 IntelliSense: expected a '(' c:\Users\CJ\Documents\Visual Studio 2012\Projects\address\address\addressbook.cpp 36 7 address 8 IntelliSense: expected a '(' c:\Users\CJ\Documents\Visual Studio 2012\Projects\address\address\addressbook.cpp 37 7 address 10 IntelliSense: expected a '(' c:\Users\CJ\Documents\Visual Studio 2012\Projects\address\address\addressbook.cpp 38 7 address 7 IntelliSense: member "addressBook::people" has already been initialized c:\Users\CJ\Documents\Visual Studio 2012\Projects\address\address\addressbook.cpp 37 1 address 9 IntelliSense: member "addressBook::people" has already been initialized c:\Users\CJ\Documents\Visual Studio 2012\Projects\address\address\addressbook.cpp 38 1 address Warning 3 warning C4018: '<' : signed/unsigned mismatch c:\users\cj\documents\visual studio 2012\projects\address\address\addressbook.cpp 68 1 address Warning 4 warning C4018: '<' : signed/unsigned mismatch c:\users\cj\documents\visual studio 2012\projects\address\address\addressbook.cpp 80 1 address Warning 5 warning C4018: '<' : signed/unsigned mismatch c:\users\cj\documents\visual studio 2012\projects\address\address\addressbook.cpp 94 1 address Warning 2 warning C4018: '>=' : signed/unsigned mismatch c:\users\cj\documents\visual studio 2012\projects\address\address\addressbook.cpp 58 1 address |
|
|
|
|
|
|
|
|
|
|
|
|