class Card
{
private: string suit; int value;
public:
Card()//default constructor (no arguments) allows you to make an
{ //array
value = 0;
}
Card(int v, string s)// allows the private attributes to be set
{
value = v;
suit = s;
}
int getvalue()// returns the cards value
{
return value;
}
string getsuit()// returns the cards suit
{
return suit;
}
};
the problem is, that i have a vector of type 'Card' and need to print out the full vector, to create the vector i have this:
void createDeck()
{
int n,i,j;
string b;
j = 0;
for(n = 1; n < 5; n++)
{
for(i = 1; i < 14; ++i)
{
switch (n)
{
case 1: b = "Hearts";
break;
case 2: b = "Spades";
break;
case 3: b = "Diamonds";
break;
case 4: b = "Clubs";
break;
};
deck1.push_back(Card(i, b));
}
}
}
how do i go about accessing the value and suit from 'deck1[x]' (for loop prefreble). when i place a dot (.) afterwards, it gives me vector options, not my class options.
#include <iostream>
#include <string>
usingnamespace std;
class Card
{
private: string suit; int value;
public:
Card()//default constructor (no arguments) allows you to make an
{ //array
value = 0;
}
Card(int v, string s)// allows the private attributes to be set
{
value = v;
suit = s;
}
int getvalue()// returns the cards value
{
return value;
}
string getsuit()// returns the cards suit
{
return suit;
}
};
Yeah, you're including "class.cpp" twice in main.cpp. First directly, then indirectly via "deck class.cpp".
Didn't your book teach you about translation units and header/source files?