Jump to content

[SOLVED] Problem with Reflection Class


photo

Recommended Posts

Hello.

 

Why an error occurs during processing of user class with vector by Reflection Class?

For example, I have the following class:

class MyClass
{
	private:
	
	int myVector[0] = (1, 2, 3);
	
	public:
	
	MyClass() {}
	
	void addItem(int value)
	{
		myVector.append(value);
	}
	
	int getItem(int num)
	{
		return myVector[num];
	}
	
	int getNumItems()
	{
		return myVector.size();
	}
};

I use this class in Init() function:

int init() 
{	
	MyClass my_class = new MyClass();
	
	my_class.addItem(4);
	
	forloop(int i = 0; my_class.getNumItems())
	{
		log.message("item[%d] = %d;\n", i, my_class.getItem(i));
	}
	
	/* Output:
	*	item[0] = 1;
	*	item[1] = 2;
	*	item[2] = 3;
	*	item[3] = 4;
	*/

	Reflection my_reflection = new Reflection();
	
	my_reflection.reflect(my_class); // here is an error
	
	return 1;
}

And i have following error:

 

Assertion: '(unsigned int)index < (unsigned int)length && "Vector::operator[](): bad index" '

 

error.png

 

Update:

 

I initialize the vector in constructor, but the probled remained. Then I just declared a variable in the class and the problem disappeared. But this variable is unused.

Code:

class MyClass
{
	private:
	
	int myVector[0];
	
	int i;
	
	public:
	
	MyClass() 
	{
		myVector = (1,2,3);
	}
	
	void addItem(int value)
	{
		myVector.append(value);
	}
	
	int getItem(int num)
	{
		return myVector[num];
	}
	
	int getNumItems()
	{
		return myVector.size();
	}
};
Edited by sergey.pozhidaev
Link to comment
×
×
  • Create New...