Template instantiation & inheritance - fixed, but can I scrap the warning I get to do it?

John Graham johngavingraham@googlemail.com
Sun Feb 28 02:28:00 GMT 2010


> Can you post a minimal example?

An example of which bit? The only one I've made up so far is attached.
It shows a basic configuration that compiles when the template
instantiations are in a header file that's included in several
translation units - set CFLAGS to define SUPER and/or SUB to include a
particular template instantiation.

However, the example attached doesn't *quite* show what I had in
practice - the only difference is that when I instantiate the
templates in a header file in my real library, I don't have to do
anything for the superclass - that all just seems to get generated.
However, in the example attached, you don't get the superclass's
template information unless you instantiate it separately.

John G


On Sat, Feb 27, 2010 at 4:24 PM, Brian Budge <brian.budge@gmail.com> wrote:
> Hi John -
>
> I was surprised to see that compile :).  You should be placing explicit
> instantiations in a source file.  I'm not sure why it didn't work before.
> Can you post a minimal example?
>
> On Feb 27, 2010 5:19 AM, "John Graham" <johngavingraham@googlemail.com>
> wrote:
>
> Okay, I seem to have gone and answered my own question!
>
> For some reason I couldn't do:
>
>
> template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
> ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;
>
>
> Because I'd get a few of the following back:
>
>
> ccrtp/rtp.h: In member function 'ost::IPV4Host
> ost::TRTPSessionBase<RTPDataChannel, RTCPChannel,
> ServiceQueue>::getDataSender(ost::tpport_t*) const [with
> RTPDataChannel = ost::RTPBaseUDPIPv4Socket, RTCPChannel =
> ost::RTPBaseUDPIPv4Socket, ServiceQueue = ost::AVPQueue]':
> rtpaudioport.cpp:24:   instantiated from here
> ccrtp/rtp.h:205: error: no matching function for call to
> 'ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t*&)'
> ccrtp/channel.h:114: note: candidates are: ost::IPV4Host
> ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t&) const
>
>
> But I can do:
>
>
> inline template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
> ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;
>
>
> And that seems to generate the necessary class information.
>
> Still seems like a bit of a mystery that this has to be specifically
> generated though... is there a reason for that?
>
> Also, I have to turn off -pedantic-errors to compile that, as it's a
> non-standard extension. Is there any way I can specify an
> -fno-<something> option to turn this error off:
>
> error: ISO C++ forbids the use of 'inline' on explicit instantiations
>
>
> Thanks again,
>
> John G
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: temp-inst.tar.bz2
Type: application/x-bzip2
Size: 6575 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20100228/b265bf37/attachment-0001.bz2>


More information about the Gcc-help mailing list