Member Initilize List

I have a question, about the member initiziler list.
I want to know if you can use the member initilizer list with a function? Or if its only able to be used with the constructors?

1
2
3
4
5
 void AmmunitionManager::load() // mLocation(x,y)can i do this?
                               // It doesnt work when i try:
 AmmunitionManager::AmmunitionManager(int x, int y):mLocation(x,y)//Can i only
                                                               // do it like this?
                               


Heres a bit more info on the class.
Im trying to create a 'new' Point But its having issues.
I want to pass 2 ints a x and y, becausue thats what my point class has. And i can use it with a constructor but not a void functionName();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef AMMUNITIONMANAGER_H
#define AMMUNITIONMANAGER_H
#include "Ammunition.h"
#include "point.h"
class AmmunitionManager
{
protected:
	const int miSize;
	Point mLocation;		// member initialise //point(default con,custom con)?
	Point* mpLocation;		// new //pointer to point (defualt con,custom con)?
	Ammunition **ammo;
public:
	AmmunitionManager();	//default
	AmmunitionManager(int,int,int); //Custom size the Ammo array of pointers
	~AmmunitionManager();
	bool init();
	void load();
	void setload(int);
	int getload();
	void setSize(int);
	int getSize();
	Point* getLocation();
	Point* get_pLocation();
	//Point *getPoint();

};
#endif 

Last edited on
You'll need to show more content. What type of variable is mLocation?
its a Point.
I have the following variables in my AmmunitionManager class
const int miSize;
Point mLocation;
Point* mpLocation;
Ammunition **ammo;
Then in your constructor you'll probably need to use the Point constructor.

AmmunitionManager::AmmunitionManager(int x, int y) : mLocation(Point(x,y))

Provided of course that the Point class has a constructor that takes two int arguments.

Edit: And be careful of all those pointers. You really should initialize them in the initialization list as well.
Last edited on
Topic archived. No new replies allowed.