Skip to content

redefinition of '...' as different kind of symbol when trying to use an interface more than once #309

@joergbrech

Description

@joergbrech

This example on cppx.godbolt introduces an interface that injects code into a class. If I try to use the interface twice, e.g. by defining a second class Foo after Shape like this:

class Foo(interface) {};

I get a compilation error:

error: redefinition of 'interface' as different kind of symbol

https://cppx.godbolt.org/z/MMx1jxoqf

At first sight this looks like a parsing issue to me (class interface instead of class(interface)), but then I wonder why it works for the first use....


Use Case: I tried to implement an interface equality_comparable that injects a bool operator==()(X const& other) method into a class, similar to the #[derive(PartialEq)] attribute in rust or the defaulted comparison operators (as of C++20).

Injecting the code into the classes directly works: https://cppx.godbolt.org/z/W5hzojM6o, injecting via interface fails with the above error: https://cppx.godbolt.org/z/nor384hWb


PS: This is an awesome powerful proposal. I would love to see it happen!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions