473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

create object by using new, error in compilation

254 100+
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 1622
Ganon11
3,652 Expert 2GB
Have you initialized the Set powerups in your .cpp file?
Jan 4 '07 #2
nickyeng
254 100+
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
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...
7
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...
1
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...
4
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...
0
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...
1
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...
3
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; class Base { public: Base(int x = 0);
7
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>;...
6
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.