Date: Fri, 06 May 2022 10:17:33 +0100
Hi,
Implicit instantiations of class templates don't instantiate the definitions of functions within the class. I don't think that friend functions are an exception.
Cheers,
Lénárd
On 6 May 2022 09:46:11 BST, Yongwei Wu via Std-Discussion <std-discussion_at_[hidden]> wrote:
>Sorry, I think I misunderstood your problem in my last email. It is not
>really about friends (though it can cause troubles), but the instantiation
>moment. David pinned it: the function would be available as long as you
>instantiate S::X<256>.
>
>On Thu, 5 May 2022 at 17:28, Vladimir Grigoriev via Std-Discussion <
>std-discussion_at_[hidden]> wrote:
>
>> Try this code
>>
>> https://gcc.godbolt.org/z/Mrb3WzMv7
>>
>> If to write
>>
>> inline X<256> operator+(const X<256>&, const X<256>&) noexcept;
>>
>> then the error message is
>>
>> <source>:24: undefined reference to `S::operator+(S::X<256u> const&,
>> S::X<256u> const&)'
>>
>>
>>
>>
>> You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or
>> http://ru.stackoverflow.com
>>
>
>--
>Yongwei Wu
>URL: http://wyw.dcweb.cn/
Implicit instantiations of class templates don't instantiate the definitions of functions within the class. I don't think that friend functions are an exception.
Cheers,
Lénárd
On 6 May 2022 09:46:11 BST, Yongwei Wu via Std-Discussion <std-discussion_at_[hidden]> wrote:
>Sorry, I think I misunderstood your problem in my last email. It is not
>really about friends (though it can cause troubles), but the instantiation
>moment. David pinned it: the function would be available as long as you
>instantiate S::X<256>.
>
>On Thu, 5 May 2022 at 17:28, Vladimir Grigoriev via Std-Discussion <
>std-discussion_at_[hidden]> wrote:
>
>> Try this code
>>
>> https://gcc.godbolt.org/z/Mrb3WzMv7
>>
>> If to write
>>
>> inline X<256> operator+(const X<256>&, const X<256>&) noexcept;
>>
>> then the error message is
>>
>> <source>:24: undefined reference to `S::operator+(S::X<256u> const&,
>> S::X<256u> const&)'
>>
>>
>>
>>
>> You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or
>> http://ru.stackoverflow.com
>>
>
>--
>Yongwei Wu
>URL: http://wyw.dcweb.cn/
Received on 2022-05-06 09:17:39