template member function

  • Thread starter Alexander Stippler
  • Start date
A

Alexander Stippler

Hey all,

what exactly is forbidden/wrong with the following call of a template
member function;

template <typename T>
struct Base
{
template <int N>
void
cio();
};

template <typename T>
struct Derived
: public Base<T>
{
template <int N>
void
cio()
{
Base<T>::cio<N>(); // !!!!!! <--- what's the
problem here?
}
};

int
main()
{
}

Best regards,
Alex
 
S

Sam

Alexander said:
Hey all,

what exactly is forbidden/wrong with the following call of a template
member function;

template <typename T>
struct Base
{
template <int N>
void
cio();
};

template <typename T>
struct Derived
: public Base<T>
{
template <int N>
void
cio()
{
Base<T>::cio<N>(); // !!!!!! <--- what's the
problem here?
}
};

int
main()
{
}

Sometimes the parsing rules, when templates are involved, get a bit hairy
and what might seem obvious to a meatbag, is not so obvious to a mechanical
parser, to you have to give the compiler a bit of help. Rewriting the
offending statement as:

Base<T> *b=static_cast<Base<T> *>(this);

b->cio<N>();

This should do what you want.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBH1CICx9p3GYHlUOIRAuKiAJ9O2CngmUz5CywT09XVKNUpqchGvQCfXOuM
3uV5MPry+XjrQfJe5t7mAFU=
=9V16
-----END PGP SIGNATURE-----
 
W

witmer

Hey all,

what exactly is forbidden/wrong with the following call of a template
member function;

template <typename T>
struct Base
{
    template <int N>
        void
        cio();

};

template <typename T>
struct Derived
    : public Base<T>
{
    template <int N>
        void
        cio()
        {
            Base<T>::cio<N>();           // !!!!!!  <---   what's the
problem here?
        }

};

int
main()
{

}

The parser doesn't know that cio is a template.
Try:

Base<T>::template cio<N>();
 
A

Alexander Stippler

This is a MIME GnuPG-signed message. If you see this text, it means that
your E-mail or Usenet software does not support MIME signed messages.
The Internet standard for MIME PGP messages, RFC 2015, was published in 1996.
To open this message correctly you will need to install E-mail or Usenet
software that supports modern Internet standards.

--=_mimegpg-commodore.email-scan.com-29220-1205084674-0001
Content-Type: text/plain; format=flowed; charset="US-ASCII"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit



Sometimes the parsing rules, when templates are involved, get a bit hairy
and what might seem obvious to a meatbag, is not so obvious to a mechanical
parser, to you have to give the compiler a bit of help. Rewriting the
offending statement as:

Base<T> *b=static_cast<Base<T> *>(this);

b->cio<N>();

This should do what you want.


--=_mimegpg-commodore.email-scan.com-29220-1205084674-0001
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBH1CICx9p3GYHlUOIRAuKiAJ9O2CngmUz5CywT09XVKNUpqchGvQCfXOuM
3uV5MPry+XjrQfJe5t7mAFU=
=9V16
-----END PGP SIGNATURE-----

--=_mimegpg-commodore.email-scan.com-29220-1205084674-0001--

Thanks a lot. It should have been obvious to me. I even knew your
solution long time ago :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top