| Xendraw (54) | |||||||
in my class, i wish to print a vector of objects via pointers, so that i can add certain functions later, anyway here is my class now:
as you can see the printdeck function isn't using pointers yet, i need it to print using the pointers created in the constructor, just in case, here is the class of the card:
and this is the my main (includes the function that creates the deck):
| |||||||
|
|
|||||||
| clanmjc (526) | |||||
Just do this?
in replace of.. in all your code
Is this what you are asking? | |||||
|
Last edited on
|
|||||
| Xendraw (54) | |
| yes, i thought it was that as well, however it makes my program crash | |
|
|
|
| bluecoder (738) | |
| but why do you want to use pointer in the vector ? | |
|
|
|
| clanmjc (526) | |||||
Here is one problem.
pcardvector contains no elements, its size is 0, trying to index into the vector is going to fail. You will need to push_back(&cardvector[x])
Once you make these changes call the pointer vector like you think it should be called. | |||||
|
|
|||||
| Xendraw (54) | |||
something like that? | |||
|
|
|||
| clanmjc (526) | |
Like this.pcardvector.push_back(&cardvector[x]);
| |
|
|
|
| Xendraw (54) | |
| oh, i understand that now, the same way i have done in the createdeck function, yes? | |
|
|
|
| bluecoder (738) | |
|
cool .. clanmjc .. good thing to know ..thanks but how do i display the value which is in pcardvectori mean to say how do i display the value of cardvector which is stored in pcardvector; thanks xxx | |
|
|
|
| Xendraw (54) | |
| that would also be useful to know, thanks for asking blue | |
|
|
|
| clanmjc (526) | |
After making the suggested changes above, replace your calls to the cardvector outputs with pcardvector[x]->getSuite(). | |
|
|
|
| Xendraw (54) | |
| it has warnings where the for loop arguement is, saying : trying to compare signed and unsigned variables, and the program doesnt actually output anything | |
|
|
|
| clanmjc (526) | |
| Which line? | |
|
|
|
| Xendraw (54) | |||
19 and 27
| |||
|
|
|||
| clanmjc (526) | |
| Thats because vector.size returns size_t, you can change your indices to size_t instead of int and that warning will go away. | |
|
|
|
| Xendraw (54) | |
| what is size_t? i have never heard of that before | |
|
|
|
| Xendraw (54) | |
| ok that compiles with no warning, but it still displays nothing upon running, just returns zero | |
|
|
|
| clanmjc (526) | |
| Post all your modified code. | |
|
|
|
| Xendraw (54) | |||||||
|
you are the boss: main:
deck class:
card class:
| |||||||
|
|
|||||||
| clanmjc (526) | |
Do you see the problem here?for (size_t x; x < pcardvector.size(); ++x)
| |
|
|
|