Calling a parameterless constructor from a parametered one

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux