Class template questions

Asked 2 years ago, Updated 2 years ago, 124 views

template class Sample { private: struct NODE { DATA s_data; BYTE s_checksum;

        NODE()
        {
            s_checksum = CHECK_SUM;
        }
    };
}

The class template is defined as above, and I want to use another class in the DATA section The problem is that there are no default generators for the class you want to put in DATA, but there are only generators with one int, and I don't know how to call them.

External class round class test { public: test(int a) { } }

Calling a class template Sample sample(...);

How can the constructor of the test be called correctly when writing in this way?

class template

2022-09-22 15:55

1 Answers

Can't we just call the value of s_data in the Node default constructor? If you don't understand exactly why you can't call if you have 1 arg c'tor instead of the default constructor, I'll give you a few examples.

You can also give default parameters to write like the default raw scribe.

class Data
{ 
public:
    // Default Parameters
    Data(int a = 0)
    {
    }
};

And in the sample class,

template <typename Data>
class Sample 
{ 
public:
    struct Node
    {
        Data s_data;
        Byte s_checksum;    

        node()
            : : s_data()
        {
            s_checksum = CHECK_SUM;
        }
    }
};

However, it usually initializes all member variables when using a constructor or destructor. This is where you can call.


2022-09-22 15:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.