开发者

Do I need to specify attributes on deriving classes?

开发者 https://www.devze.com 2023-01-20 18:29 出处:网络
I have this interface. If I derive, do I need to specify forma开发者_Python百科t attribute again? And, if a class Deriv implements this interface, can I use Deriv::LT_DEBUG?

I have this interface. If I derive, do I need to specify forma开发者_Python百科t attribute again? And, if a class Deriv implements this interface, can I use Deriv::LT_DEBUG?

class Logger
{
    public:
        enum LogType
        {   
            LT_DEBUG = 0,
            LT_WARNING,
            LT_ERROR,
            LT_STAT,
            LT_TEXT
        };  

        __attribute__((format(printf, 6, 7)))
        virtual const char* EHLog(LogType,
                bool,
                const char*,
                int,
                const char*, 
                ...) = 0;

        virtual ~Logger(){}
};


I could not find any documentation on it, but I guess that the __attribute__ annotation is not implicitly inherited by a derived class.
This means that, if you call EHLog through a Deriv instance, reference or pointer, the format checking is only done if the Deriv::EHLog also specifies the __attribute__((format)) annotation.

The reason for my guess is that this way the compiler does not have to change its name-lookup mechanism to cope with the possibility of __attribute__ annotations on the base-class function that is being overridden.


As for the second question: Yes, you can access names from the base class using a derived class qualification. Deriv::LT_DEBUG should work and resolve to the same name as Logger::LT_DEBUG.

0

精彩评论

暂无评论...
验证码 换一张
取 消