Question

I find the syntax of the constructor inheritance slightly odd. The example below works well, but I do not understand why I need to specify using sysTrajectory::sysTrajectory and not using sysTrajectory<Real>::sysTrajectory<Real> when inheriting from a class template? The latter gives the following error: expected ‘;’ before ‘<’ token using sysTrajectory<Real>::sysTrajectory<Real>;.

class sysRealTrajectory: public sysTrajectory<Real>
{

    public:

    /**
        *   Default constructor
        */
        inline sysRealTrajectory(void);

        using sysTrajectory::sysTrajectory;     

        /**
        *   Default destructor
        */
        inline ~sysRealTrajectory(void);
};

main :

Real a;
a=5;
sysTrajectoryPoint<Real> TP0(1.0,a);
sysRealTrajectory Trajectory(TP0);
Was it helpful?

Solution

This syntax

using sysTrajectory::sysTrajectory; 

Names all constructors of sysTrajectory. This syntax

using sysTrajectory::sysTrajectory<Real>;

Names only a constructors that accept a template argument <Real> (yes, you can do that, you can pass explicit template arguments to constructors in declarative contexts). Your base class does not appear to have any constructor templates, so your compiler's parser does not take sysTrajectory as a template-name and hence does not accept the < as an opening template argument list. Hence the syntax error.

For a template-name to be explicitly qualified by the template arguments, the name must be known to refer to a template.

Even if you had a constructor template, a rule for using declarations forbids that too. It says

A using-declaration shall not name a template-id.

OTHER TIPS

In gcc 4.8.1 the following syntax works for me:

using sysTrajectory<Real>::sysTrajectory;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top