But they are functions...thats what I'm saying...except PlayerIO a(), thats me attempting to construct an object. You had said to construct an Object it was ObjectType o(parameters); but if I have no parameters shouldn't it just be ObjectType o();
But they are functions...thats what I'm saying...except PlayerIO a(), thats me attempting to construct an object. You had said to construct an Object it was ObjectType o(parameters); but if I have no parameters shouldn't it just be ObjectType o();
Yes, that's one of the interesting inconistencies that came out of trying to retrofit object orientation into an already existing language.
How would you declare a function that takes no parameters that return an object of ClassA? If we assume this is:
then how do you expect the compiler to tell the difference from that and the "no parameters" construction, constructing a variable called func?Code:ClassA func();
Since one form already existed originally in C (the former), the latter had to be the one that differs. [A bit like the joke about the ship sending a message to the lighthouse to "move to your left" - it ain't no good trying to move something solid!]
--
Mats
Ok well I took the parenthesis away and it worked, now to just clean up the rest of the program.
I'm doing a lot of substring work, which is kind of annoying because it seems to not work the way I want it. For example, I have a line of text that looks like this:
After some annoying substring manipulation I get it down to this:Code:Nick Swisher</td> 1B/0F</td> 266.9</td>
I need to be able to realize that this line of text contains 1B and 0F so I tried this:Code:1B/0F</td> 266.9</td>
If the / comes before the </td> it means I have more than one position, otherwise it'll pick up the / in </td> and there will only be one position. However,when I want to print out the positions it doesn't give me what I want. This line fore example prints "1B and 0F</t"Code:int secpos = line.find("/"); int endpos = line.find("</td>"); if(secpos < endpos)//more than one pos { pos1 = line.substr(0,secpos); pos2 = line.substr(secpos+1,endpos); } else pos1 = line.substr(0,endpos);
I think I'm using substr wrong. I was thinking it'd be easier to just replace all of the occurences of </td> with something but I'm not sure how to do that either
Last edited by jcafaro10; 07-31-2007 at 08:11 AM.
You are using substr wrong - the second parameter is the length, not the position to end at...
--
Mats
Ok, that makes sense...does C++ have arraylists or lists of any kind like Java does?
Last edited by jcafaro10; 07-31-2007 at 01:18 PM.
Yes, the standard library has a bunch of containers. vector is a dynamic array, deque is a double-ended queue, list is a doubly linked list, map is a sorted map, set is a sorted map where the key and value are a single object, multimap and multiset are versions of map and set that allow duplicates. I might be forgetting some. There are also adapters that confine the behavior of one of the ones above to a specific interface, like stack or queue. There are not-quite standard containers called unordered_map, unordered_set, unordered_multimap and unordered_multiset that are not sorted and use a hash based implementation.
For many needs, a vector is a good start. I'd try that first.
I wanted to make the vector a variable in the headerfile for PlayerIO but then I have to include Player.h in PlayerIO.h, and then I get a lot of errors. Is this the best way to do that or should vectors not go into headerfiles
Last edited by jcafaro10; 07-31-2007 at 02:51 PM.
This is how it's currently laid out, with comments to show how I want it to be laid out
PlayerIO.h
PlayerIO.cppCode:#include <vector> #include "Player.h" using namespace std; class PlayerIO { vector<Player> allPlayers; public: PlayerIO(); void makePlayerList(); void sortList(); };
Code:#include <vector> #include "PlayerIO.h" #include "Player.h" using namespace std; PlayerIO::PlayerIO() { } void PlayerIO::makePlayerList() { Player a(stuff); allPlayers.push_back(a); } void PlayerIO::sortList() { for(int i = 0; i<allPlayers.length; i++) stuff; }
Last edited by jcafaro10; 07-31-2007 at 03:19 PM.
So, I take it the errors/warnings are simply because you include "player.h" twice? You need include-guards, as discussed previously in this thread.
--
Mats
Error 1 error C2011: 'Player' : 'class' type redefinition
When I actually make the changes I wanted to make (I'll edit that code) I get this error.
I don't understand, the guards are so I don't include it more than once? But don't I need to because differetn classes need to use it? PlayerIO.cpp needs to include Player.h so it can add Players to a list of Players. PlayerIO.h needs to include Player.h so it can make an actual vector of Players.
EDIT: OH! PlayerIO.cpp includes PlayerIO.h and Player.h but PlayerIO.h already includes Player.h...so I just didn't include Player.h in PlayerIO.cpp...problem solved
Last edited by jcafaro10; 07-31-2007 at 03:28 PM.
Yes, but the CORRECT way to solve that problem is to have include-guards so that the include file is taken only once, whether you include it once or a hundred times. Consider that somone may not KNOW that you shouldn't include player.h when using playerIO.h. Or someone writes a piece of code that uses player, then needs playerIO too, and adds playerIO.h to the .cpp file, and suddenly all h**l breaks loose in the form of errors and warnings.
--
Mats