473,789 Members | 3,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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<iostre am>
using namespace std;
class Test
{

private:
int life;

public:
void player_test_lif e()
{
if(life <= 0)
{
cout << "Your dead" << endl;
}
else
{
}
}
void player_minus_li fe()
{
life=100;
while(life != 0)
{
--life;
Test::player_te st_life();

}
}
};

int main()
{
Test::player_mi nus_life();
return 0;
}
Greetings Tobias, I am a new member of this group....

Sep 28 '07 #1
3 1658
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<iostre am>
using namespace std;
class Test
{

private:
int life;

public:
void player_test_lif e()
{
if(life <= 0)
{
cout << "Your dead" << endl;
"You're dead"
}
else
{
}
}
void player_minus_li fe()
{
life=100;
while(life != 0)
{
--life;
Test::player_te st_life();

}
}
};

int main()
{
Test::player_mi nus_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
Sep 28 '07 #2
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<iostre am>
using namespace std;
class Test
{

private:
int life;

public:
void player_test_lif e()
{
if(life <= 0)
{
cout << "Your dead" << endl;
}
else
{
}
}
void player_minus_li fe()
{
life=100;
while(life != 0)
{
--life;
Test::player_te st_life();

}
}
};

int main()
{
Test::player_mi nus_life();
Try:
Test player;
player.player_m inus_life();

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

Alan
Sep 28 '07 #3
ThaDoctor wrote:
>
int main()
{
Test::player_mi nus_life();
return 0;
}
It seems like you forgot to instantiate an object of the class Test.
Sep 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2138
by: Rich S. | last post by:
Hello Just like everyone else, I am excited about how easily one can create Windows applications with the .NET platform, but for shareware, I have some serious reservations 1. Your code can be easily decompiled. This would make it very difficult to implement any sort of license restrictions on your app, because anything you write can be easily viewed and cracked. This also removes any privacy for your intellectual property 2. Jim...
1
1566
by: Claude Vernier | last post by:
Hello, I'm a C# programmer. I have two projects. First, write an action scrolling game in C#, (portable to Windows Mobile eventually...), This game will look like The Adventure of Link from Nintendo, or Super Mario Bros... I didn't planned to use DirectX since all tutorials I have seen for DirectX are for 3D.
17
4579
by: Valerie | last post by:
Ok. Help. the quarter is ending soon and I have no interest in creating games. I think that's why i have a mental block on this particular lab assignment. I'm using the same book as Steven Smith is using when One Handed Man helped him. And, I don't even know where to continue. The application is a tic tac toe game.
10
2096
by: connyledin | last post by:
Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file: http://esnips.com/webfolder/b71bfe95-d363-4dd3-bfad-39999a9e36d0 What i have the biggest problems with now is between line 8 and 23. How i can move the character trough the game. Other parts of the game that have with the movement to do is between line 83-114 and...
1
3175
by: Disccooker | last post by:
i am trying to use XPath and the XMLDataSource to display data from an XMLDocument and am getting nowhere. What i would like to do is have a repeater display a label for Seed, label for Team Name and a Text Box for each game - like an NCAA bracket. 1. Team1 16. Bradley 8. Missouri 9. USM
45
4557
by: Gaijinco | last post by:
Hi my name is Carlos Obregón and I'm currently a profesor of C/C++ programming at the CUMD in Bogotá Colombia. This last term I ask my students to develop an implementation of the minesweeper game with ASCII graphics and input via keyboard. I'm trying to look for other games suitable to those restrictions. Does anyone knows a good candidate?
1
2639
by: idsh | last post by:
I cant make this code work. I am new at Python, and in this program I have made a simple mastermind program. After creating the widgets, I try to insert text in the textbox in a function but all I get is "NameError: global name 'display_txt' is not defined" for the textbox I have created earlier in the widgets What am I missing???!!!! Here is some code (part of it) def display_instruct(): message = """This is a master mind game...
4
2500
by: softwaregeek | last post by:
hi to all, I am having some problem in passing parameter..... My code looks like::: request.setAttribute("game",game); response.sendRedirect("profile.do?operation=select&max_profiles="+totalprofiles+"&fsa="+fsa+"&score="+score+"&gameid=" + gameid + "&locale="+locale);
1
3776
by: SerialChick | last post by:
Hi, So i created a form called board. and on this form placed a whole heap of labels, buttons and a menu. Now from the menu there is a New Game option. When this is clicked a new form is opened called New Game. once you are finished filling in details the New Game form disappears. The board form is still there, has always been there but now i want certain labels to turn invisible. so in the board class i have all the VS2005 code making all...
0
9665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.