RE: Calling a parameterless constructor from a parametered one

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

 



The statement
//    baseClass(T val)
//       : baseClass()
//{
is wrong I think and isn't needed since you have
   baseClass(T val)
      : theVal(val)
   {
   }
========================================
#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();
}

-----Original Message-----
From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx]On
Behalf Of Fred Labrosse
Sent: Monday, April 18, 2005 1:59 PM
To: gcc-help@xxxxxxxxxxx
Subject: 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


[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