Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Simple class embedding question

Reply
Thread Tools

Simple class embedding question

 
 
hexusnexus@gmail.com
Guest
Posts: n/a
 
      04-09-2008
Hi. I just downloaded Visual C++ Express, and I converted my C code
to C++. The problem I'm having is that I'm declaring a new class
instance inside another class definition, and I can't get access to
the data. Actually, I'm using structs, but they're only default public
classes anyway, so I know at least that it can't be a problem with
protected or private.

Here's a snippet of the code:


/****germanwhist.h*****/

struct Hand
{
Card cards[13];
int length;
Hand()
{
length=0;
}
bool operator! ()
{
int i;
bool j;
for (i=0; i < Len(); i++)
{
if (cards[i].raw==-1)
{
j=true;
break;
}
if (j==true) return true;
else return false;
}
}
Card pull(int pos=0)
{
Card temp;
temp = cards[0];
cards[0] = Card();
length--;
return temp;
}
Card pullName(string name)
{
Card pulled;
for (int i=0; i < Len(); i++)
{
if (cards[i].name==name)
{
pulled=pull(i);
break;
}
}
return pulled;
}
void put(Card crd)
{
cards[length] = crd;
length++;
}
Card* inSuit(Card trump)
{
Card temp[13];
for (int i=0; i < Len(); i++)
if (cards[i].s==trump.s) temp[i]=cards[i];
return temp;

}
Card* notinSuit(Card trump)
{
Card temp[13];
for (int i=0; i < Len(); i++)
if (cards[i].s!=trump.s)
temp[i]=cards[i];
return temp;
}
Card* allSuits()
{
return cards;
}
void organize(Card trump)
{
Card temp;
int i, j, k, l, m, begin, end;
for (i=0; i<Len(); i++)
{
for (j=0; j<Len()-1; j++)
{
if (cards[j].raw > cards[j+1].raw)
{
temp = cards[j+1];
cards[j+1] = cards[j];
cards[j] = temp;
}
}
}

//move trumps to top
for (i=Len()-1; i>-1; i--)
if (cards[i].s == trump.s) break;

end = i;
if (end<0) end=0;

for (i=end; i>-1; i--)
if (cards[i].s != trump.s) break;

begin = i;

m=Len()-1;
for (j=end; j > begin; j--)
{
l=0;
k=j;
while (true)
{
l=k+1;
if (l > m) break;
temp = cards[l];
cards[l] = cards[k];
cards[k] = temp;
k=l;
}
m--;
}
//move negative (null) cards to the top to be ignored
if (Len()<13)
{
for (i=0; i<Len(); i++)
{
for (j=0; j<Len()-1; j++)
{
if (!cards[j])
{
temp = cards[j+1];
cards[j+1] = cards[j];
cards[j] = temp;
}
}
}
}
}
int Len()
{
return length;
}
};

struct Player
{
Hand hand;
string name;
int tricks;
Player(string nname)
{
name = nname;
tricks = 0;
}
void receiveCard(Card crd)
{
hand.put(crd);
}
void wonTrick()
{
tricks++;
}
void organize(Card trump)
{
hand.organize(trump);
}
int Len()
{
return hand.length;
}
};

****germanwhist.cpp****
int main()
{
Player player("Player");
... //add cards to player hand
cout << .player.Len() << endl;
system("pause");
return 0;
}

//player.Len() should return the number of cards in the player hand.
But it always returns 0. I've searched
//throughout the code and I can't seem to find any answers. Anybody
have any ideas?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple? embedding question sndive@gmail.com Python 7 10-31-2007 05:00 PM
Failing in a simple embedding example of python Themistoklis Bourdenas Python 0 03-01-2006 08:46 AM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM



Advertisments