zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    关于C的struct结构的几个常见疑问。
    NAT类型
    Linux oops stack 分析
    关于pci_dev的定义
    还是动态添加控件 触发事件
    页面编译模型
    MDX 销售额与上月比较
    C语言的词法语法分析lex&yacc 经典收藏
    interrupt storm
    js获取mac地址
  • 原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/2871096.html
Copyright © 2011-2022 走看看