How do I copy a const array to a pointer?

I have a static const array:

const int TrollClass::abilities[ABILITY_MAX] = {14,23,6,6,23,9};


I want to send it through this method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool CreatureClass::InitAbilities(int* val) {

	int* tmp = new int[ABILITY_MAX];
	
	for (int i = 0; i < ABILITY_MAX; i++) {  
		if (val[i] >= 0)		        
			tmp[i] = val[i];
		else  
			return false;      // if any ability < 0 
	}                          // return false
	
	CopyIntoAbil(tmp);         // copy tmp into abilities if  
	return true;               // since all are valid
}




When I try it I get this compiler error:

1
2
3
4
Source/Troll.cpp: In constructor ‘TrollClass::TrollClass(std::string)’:
Source/Troll.cpp:37:43: error: invalid conversion from ‘const int*’ to ‘int*’
Source/Troll.cpp:37:43: error:   initializing argument 1 of ‘bool CreatureClass::InitAbilities(int*)’
make: *** [Source/Troll.o] Error 1
Last edited on
You have to make the function take a const int* instead.
Topic archived. No new replies allowed.