I am confused!

void AnimationEngine::AddAnimationSet(Animation* animations)
{
	AnimationSet* newSet = new AnimationSet();

	for(int i = 0; i < (sizeof(animations) / sizeof(Animation)); i++)
	{
		for(int n = 0; n < animations[i].AnimationConditions.size(); n++)
		{
                     //newSet->conditions is of type std::vector<std::vector<myType>>
                     //animations[i].AnimationConditions is of type std::vector<myType>
			newSet->conditions[i] = animations[i].AnimationConditions;
		}
	}	

        //Stuff unrelated to error...
}

Getting a "no operator "=" matches these operands"

Dani AI

Generated

Clarification and concise fixes (building on and ):

Two separate problems are likely getting mixed up: element counting and safe vector access/assignment. The expression that uses sizeof on the function parameter won't give the number of animations because Animation* animations is a pointer in the function signature — sizeof returns the pointer size, not the array length. Also, operator[] on newSet->conditions requires that the vector already has an element at that index; indexing beyond size() is undefined behavior.

A safer approach is to accept a container that knows its size and copy each inner vector into conditions with push_back (no manual counting, no indexing surprises):

void AnimationEngine::AddAnimationSet(const std::vector<Animation>& anims) {
    AnimationSet* newSet = new AnimationSet();
    newSet->conditions.reserve(anims.size());
    for (const auto &a : anims)
        newSet->conditions.push_back(a.AnimationConditions);
    // ...
}

If using a raw array is unavoidable, pass the element count alongside the pointer and either resize() newSet->conditions before indexed assignment or use push_back in the loop. Example in words: call newSet->conditions.resize(count); first, then assign to conditions[i], or reserve and push each AnimationConditions.

If the compiler still reports "no operator= matches these operands", check type compatibility and assignability: confirm newSet->conditions is std::vector<std::vector<myType>> and that myType is copy-assignable. A quick compile-time check is possible with <type_traits>:

static_assert(std::is_copy_assignable<myType>::value, "myType must be copy-assignable");

Checklist summary: stop using sizeof on parameter pointers; prefer std::vector or pass a count; don't index into a vector without resizing; and verify that the inner element type supports copying/assignment. These steps resolve the common causes behind the observed error and the iteration/assignment problems noted by and .

Recommended Answers

All 3 Replies

newSet->conditions[i] = animations[i].AnimationConditions;

shouldnt you pick an entry from animations.AnimationConditions? ([n] ?)

Im trying to copy the entire vector, not an element of the vector.

>>for(int i = 0; i < (sizeof(animations) / sizeof(Animation)); i++)

I hope you know that, thats only going to run once. And for your error, are you sure its in that line? If what you say is true then it should compile.

Lets see the definition of condition and AnimationCondition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.