Can friend class be declared conditionally in C++03?

前端 未结 5 1391
半阙折子戏
半阙折子戏 2021-01-19 02:54

I want to declare a friend class only if some (compile-time) condition is true. For example:

// pseudo-C++
class Foo {
    if(some_compile_time_condition) {
         


        
5条回答
  •  生来不讨喜
    2021-01-19 03:30

    [class.friend]/3 tells this :

    A friend declaration that does not declare a function shall have one of the following forms:
    friend elaborated-type-specifier ;
    friend simple-type-specifier ;
    friend typename-specifier ;

    therefore it is not possible to conditionally declare friends of a class, without a macro.

提交回复
热议问题