Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > having a little problem with some code for a little game I am creating.

Reply
Thread Tools

having a little problem with some code for a little game I am creating.

 
 
ThaDoctor
Guest
Posts: n/a
 
      09-28-2007
Hi.

I am quite new to C++ so I think I would ask here what I am doing
wrong with this code.
I am writing a little game in a text console, but here is something
that is in no way related to the game but when I am compiling this it
yields an error....
Why is that

#include<iostream>
using namespace std;
class Test
{

private:
int life;

public:
void player_test_life()
{
if(life <= 0)
{
cout << "Your dead" << endl;
}
else
{
}
}
void player_minus_life()
{
life=100;
while(life != 0)
{
--life;
Test:layer_test_life();

}
}
};

int main()
{
Test:layer_minus_life();
return 0;
}


Greetings Tobias, I am a new member of this group....

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-28-2007
ThaDoctor wrote:
> I am quite new to C++ so I think I would ask here what I am doing
> wrong with this code.
> I am writing a little game in a text console, but here is something
> that is in no way related to the game but when I am compiling this it
> yields an error....


Do we have to guess what error it yields? Is that the game?

> Why is that


Because there must be some error in the code...

>
> #include<iostream>
> using namespace std;
> class Test
> {
>
> private:
> int life;
>
> public:
> void player_test_life()
> {
> if(life <= 0)
> {
> cout << "Your dead" << endl;


"You're dead"

> }
> else
> {
> }
> }
> void player_minus_life()
> {
> life=100;
> while(life != 0)
> {
> --life;
> Test:layer_test_life();
>
> }
> }
> };
>
> int main()
> {
> Test:layer_minus_life();


You cannot call a non-static member function without an instance of
the class. Create an instance and use the '.' operator to call your
member function

> return 0;
> }
>
>
> Greetings Tobias, I am a new member of this group....


Read the FAQ before posting your next post, please.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Giff
Guest
Posts: n/a
 
      09-28-2007
ThaDoctor wrote:

>
> int main()
> {
> Test:layer_minus_life();
> return 0;
> }


It seems like you forgot to instantiate an object of the class Test.
 
Reply With Quote
 
Alan Woodland
Guest
Posts: n/a
 
      09-28-2007
ThaDoctor wrote:
> Hi.
>
> I am quite new to C++ so I think I would ask here what I am doing
> wrong with this code.
> I am writing a little game in a text console, but here is something
> that is in no way related to the game but when I am compiling this it
> yields an error....
> Why is that
>
> #include<iostream>
> using namespace std;
> class Test
> {
>
> private:
> int life;
>
> public:
> void player_test_life()
> {
> if(life <= 0)
> {
> cout << "Your dead" << endl;
> }
> else
> {
> }
> }
> void player_minus_life()
> {
> life=100;
> while(life != 0)
> {
> --life;
> Test:layer_test_life();
>
> }
> }
> };
>
> int main()
> {
> Test:layer_minus_life();

Try:
Test player;
player.player_minus_life();

instead - you're trying to call a non-static method without an instance
to call it on.

Alan
 
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
1 little 2 little 3 little Kennedys dale Digital Photography 0 03-23-2008 01:03 PM
Game programming for kids: looking for open source 2D game developmentkit Max Kubierschky Python 10 03-31-2007 07:18 PM
I need help with card game game of war in GUI enviroment judith Java 0 11-01-2006 06:11 AM
Having a little problem with reflection fishfry Java 7 03-03-2004 10:06 AM
Java Game- Game can't find it's graphics jar file BlackHawke Java 12 01-26-2004 06:14 AM



Advertisments