This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Calling a parameterless constructor from a parametered one


All,

Could somebody tell me why the commented out constructor in the attached code 
doesn't compile (it doesn't make sense to do that in this example, but it 
would do in some code I'm currently writing ;-).

TIA,

Fred
#include <iostream>

template <class T, T defaultVal>
class baseClass
{
public:
   baseClass()
      : theVal(defaultVal)
   {
   }

   baseClass(T val)
      : theVal(val)
   {
   }
//    baseClass(T val)
//       : baseClass()
//    {
//       theVal = val;
//    }

   void printVal()
   {
      std::cout << theVal << std::endl;
   }

private:
   T theVal;
};

class intClass : public baseClass<int, 5>
{
public:
   intClass()
      : baseClass<int, 5>()
   {
   }

   intClass(int val)
      : baseClass<int, 5>(val)
   {
   }
};

main()
{
   intClass a(10);
   a.printVal();

   baseClass<int,1>b;
   b.printVal();
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]