Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Copy Constructor Syntax

Tags:

c++

I apologize in advance, my C++ is rusty...

What does

: m_nSize(sizeof(t1))

mean in the following section?

class CTypeSize
{
   public:
      template<class T>
      CTypeSize(const T &t1) :
      m_nSize(sizeof(t1))
      {
      }
      ~CTypeSize(void){ };
      int getSize(void) const{ return m_nSize; }
   private:
      const int m_nSize;
};

I understand copy constructors, but I remember the syntax as Class::Class(const Class& p). Am I thinking of something else, or is that an alternative syntax?

Thanks!

like image 896
user117046 Avatar asked Feb 20 '26 23:02

user117046


1 Answers

It has nothing todo with copy ctor. You are initializing the variable m_nSize using initializer list with the sizeof the template argument t1.

like image 72
Naveen Avatar answered Feb 23 '26 13:02

Naveen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!