473,883 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create object by using new, error in compilation

254 Contributor
I have a class, and i try to create an object of it but it give me error in compilation.

The error is something like "]b]undefined reference to 'Game::PowerUp: :powerups[/b]", in constructor of Game::PowerUp.
The error also contain another 2 error : also are undefined reference but under ~PowerUp destructor.

it compiled well actually if i dont create an object of it in test.cpp(main program to create objects), but once i coded this "PowerUp* power = new PowerUp(t, s, 4, 4);" in test.cpp, the compilation fails and give that that error message.

here is my code:
Expand|Select|Wrap|Line Numbers
  1. /*** Power Up class ***/
  2.     class PowerUp : public Health {
  3.     public:
  4.         PowerUp(
  5.             const Terrain* t,
  6.             Screen* s,
  7.             unsigned startX,
  8.             unsigned startY,
  9.             unsigned p = STD_POWER_UP
  10.         ) : Health(t, s, startX, startY, p) {
  11.             powerups.insert(this);
  12.         }
  13.             virtual ~PowerUp() { powerups.erase(this); }
  14.             virtual void Use(Character* c) {
  15.                 Health::Use(c);
  16.                 delete this;    // Powerups disappear once used
  17.             }
  18.             static PowerUp* Find(unsigned atX, unsigned atY) {
  19.                 set<PowerUp*>::const_iterator it;
  20.                 for (it = powerups.begin(); it != powerups.end(); it++) {
  21.                     if ((*it)->xPos == atX && (*it)->yPos == atY) {
  22.                         return (*it);
  23.                     }
  24.                 }
  25.                 return 0;
  26.             }
  27.             virtual char GetSymbol() const { return '@'; }
  28.     private:
  29.         unsigned power;
  30.         static set<PowerUp*> powerups;
  31.  
Jan 4 '07 #1
2 1637
Ganon11
3,652 Recognized Expert Specialist
Have you initialized the Set powerups in your .cpp file?
Jan 4 '07 #2
nickyeng
254 Contributor
thanks Ganon11,

i have settled this problem 5 minutes ago.

yes, you're right. I didn't yet initialise the powerups static variable.

Thanks.
Nicky Eng.
Jan 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2667
by: James Proctor | last post by:
Hi there, im brand new to ASP. Ive done loads of VB coding and one of my clients is intrested in a web based application, so im trying to play on and learn it a tad. However im comming across lots of problems. Up until now ive managed to sort most of them, but now im strugling. When i run my application i keep getting this. Server Error in '/WebApplication1' Application....
7
8882
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
1
3414
by: James Proctor | last post by:
Hi there, im brand new to ASP. Ive done loads of VB coding and one of my clients is intrested in a web based application, so im trying to play on and learn it a tad. However im comming across lots of problems. Up until now ive managed to sort most of them, but now im strugling. When i run my application i keep getting this. Server Error in '/WebApplication1' Application...
4
1997
by: Seok Bee | last post by:
Dear Experts, I've completed my console application and now wants to compile the application and an executable file to be run at another location. However, I've tried compiling that program in the command prompt with the following command : vbc Module1.vb /out:OEAutomation.exe /t:exe I received a lot of error messages.
0
1732
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called Photo. Any suggestions on how to solve this? i can't do much at the moment. Server Error in '/PhotoGallery' Application. -------------------------------------------------------------------------------- Cannot create/shadow copy 'Photo' when...
1
8928
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called Photo. Any suggestions on how to solve this? i can't do much at the moment. Server Error in '/PhotoGallery' Application. -------------------------------------------------------------------------------- Cannot create/shadow copy 'Photo' when...
3
2119
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; class Base { public: Base(int x = 0);
7
2168
by: Rob | last post by:
This actually compiles and works but it doesn't seem like the best code, so I was wondering is there another way to do this? template <typename Tvector<T>* addDepth(T) { return new vector<T>; } ....a templated meth...
6
8821
by: Mr. X. | last post by:
Hello. How can I create aspnetdb from scratch ? (I want a script that create all table, views, etc... on that database). Thanks :)
0
9945
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
9798
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10766
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
10422
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
9588
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
7136
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();...
1
4622
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
3241
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.