Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- //синтаксис создания шаблона
- template<typename T1, typename T2>
- class DataType
- {
- public:
- DataType(T1 value1, T2 value2)
- {
- this->value1 = value1;
- this->value2 = value2;
- }
- void DataTypeSize()
- {
- std::cout << "Значение " << value1 << " занимает " << sizeof(value1) << " байта" << std::endl;
- std::cout << "Значение " << value2 << " занимает " << sizeof(value2) << " байта" << std::endl;
- }
- private:
- T1 value1;
- T2 value2;
- };
- int main(int argc, char *argv[])
- {
- setlocale(LC_ALL, "Rus");
- srand(time(NULL));
- //объявление типа шаблона
- DataType<int, std::string> dt(5.99, "пять");
- dt.DataTypeSize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement