Class to disable copy and assign constructor

In the HPP file:

#include <stdio.h>
#include <string.h>

class ParentFirst
{
public:
    ParentFirst()
    {

    }

    ParentFirst(const char * pName, const int pAge)
    {
        strcpy(this->name, pName);
        this->age = pAge;
    }

    ~ParentFirst() {}

    virtual void Show()
    {
        printf("print in parent First \n");
    }

private:
    ParentFirst(const ParentFirst& disabled_Arg);
    ParentFirst& operator=( const ParentFirst& rhs );

    char name[20];
    int  age;
};


template<typename T1, typename T2>
class MyClass : public ParentFirst
{
public:
    MyClass(T1 t1, T2 t2);

    void Show();

private:
    T1 t1;
    T2 t2;
};

  In the CPP file

#include <stdio.h>
#include "templ.hpp"

struct TestStruct
{
    int i;
};

template<typename T> double Add(T x, int y)
{
    return x + y;
}

template<typename T1, typename T2>
MyClass<T1, T2> :: MyClass(T1 t1_Arg, T2 t2_Arg) : ParentFirst()
{
    t1 = t1_Arg;
    t2 = t2_Arg;
}

template<typename T1, typename T2>
void MyClass<T1, T2> :: Show()
{
    printf("MyClass show is comming %d \n", t1 + t2);
    ParentFirst::Show();
}

int main()
{
//    double r = Add(10, 5);
    //printf("result is %f\n", r);

    MyClass<int, int> my(10, 10);
    my.Show();

    const int j = 939;
    const int * k;

    k = const_cast<int*>(&j);
    printf("*k is %d\n", *k);

    return 0;
}

  

转载于:https://www.cnblogs.com/simonhaninmelbourne/archive/2013/01/22/2871096.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值