Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Template Circulation Definition

I am creating an intrusive pointer as follows:

class RefCounted {};

template <typename T>
concept RefCountedDerived = std::is_base_of_v<RefCounted, T>;

template <RefCountedDerived T>
class IntrusivePtr {};

When I perform a test with it, like:

class Test : public RefCounted
{
    static IntrusivePtr<Test> create();
}

The compiler complains that the class Test is not defined and cannot be the argument of __is_base_of. I assume that when the compiler reads the static function, it resolves to RefCountedDerived, but the class Test has not completed its definition. Actually, removing the static function resolves the issue.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So is there any solution to solve it without removing that static function?

>Solution :

is there any solution to solve it without removing that static function?

Yes, make it auto:

class Test : public RefCounted {
    inline static auto create();
};

// definition in header:
auto Test::create() {
    return IntrusivePtr<Test>{};
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading