In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to explore the restrictions on C++ templates. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The application of templates in C++ programming language is a very important operation skill. Its application improves the programming efficiency of programmers to a great extent.
1. Floating-point numbers cannot be used as untyped template parameters such as template class TT
2. Custom classes cannot be used as template parameters, and these custom classes are also non-type template parameters.
/ / 6-14-2009 # include using namespace std; / / # define FLOAT / / # define TEMPLATE_OBJECT # define COMMON_OBJECT # ifdef FLOAT template class TT; # endif # ifdef TEMPLATE_OBJECT template
< class T >Class TM {}; template
< TM c >Class TT; # endif # ifdef COMMON_OBJECT class TN {}; template
< TN c >Class TT; # endif
There is another, and quite important, limitation to C++ templates:
The declaration and definition of a template class or template function must be in the same file! Unless the new generation of compilers supports the keyword export.
What if the compiler doesn't support the export keyword, but we want to separate the declaration from the definition? The methods are as follows:
Write the template declaration in .h and the template definition in .cpp. It is important to note that we do not include .h in .cpp as usual, but in main.cpp, including these two things, such as:
/ / test.h template class Test {public: void print ();}; / / test.cpp template void Test::print () {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.