Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ObjectList inheritance #2582

Merged
merged 1 commit into from
Nov 14, 2022

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Nov 11, 2022

This PR fixes a bug where inheriting from a base LinkedObjectListTemplate implementation does not work as expected.

By example, consider these class definitions:

#include <Data/LinkedObjectList.h>

class BaseObject : public LinkedObjectTemplate<BaseObject>
{
public:
	using List = LinkedObjectListTemplate<BaseObject>;
	using OwnedList = OwnedLinkedObjectListTemplate<BaseObject>;
};

class ObjectOne : public BaseObject
{
public:
	using List = LinkedObjectListTemplate<ObjectOne>;
	using OwnedList = OwnedLinkedObjectListTemplate<ObjectOne>;

public:
	ObjectOne(int value) : prop1(value)
	{
	}

	int prop1;
};

void test()
{
    ObjectOne::OwnedList list;
    for(auto obj : list) {
        Serial << obj.prop1 << " ";
    }
}

This fails to compile with the error ‘class {anonymous}::BaseObject’ has no member named ‘prop1’,
because the iterator returns BaseObject instead of ObjectOne, which is incorrect behaviour.

@slaff slaff added this to the 4.7.0 milestone Nov 11, 2022
@slaff slaff merged commit 82fb1f6 into SmingHub:develop Nov 14, 2022
@mikee47 mikee47 deleted the fix/objectlist-inheritance branch November 15, 2022 20:14
@slaff slaff mentioned this pull request Dec 6, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants