Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the using statement and using compilation instruction of C++

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "C++ 's using statement and how to use using compilation instructions". In daily operation, I believe many people have doubts about how to use C++ 's using statement and using compilation instructions. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "C++ 's using statement and using compilation instructions". Next, please follow the editor to study!

1.using statement

C++ provides two mechanisms (the using declaration and the using compilation directive) to simplify the use of names in the namespace. The using declaration makes the specific identifier keys,using compilation directive make the entire namespace available.

The using declaration consists of the keyword using and the qualified name:

Using A::fetch

The using declaration adds a specific name to the declaration area to which it belongs, and after completing the declaration, we can use fetch instead of A::fetch.

Let's look at a specific example:

Namespace A {double bucket (double n) {.} double fetch; struct Hill {...};} int main () {using avatar fetch; cin > > fetch; fetch + = 1.0; A::Hill hill;}

If we use the using declaration outside the function, we will add the name to the global namespace:

Void test () {cout fetch; fetch + = 1.0; A::Hill hill;} 2.using compilation instruction

The using declaration makes only one name available, while the using compilation directive makes all names available. The using compilation instruction consists of a namespace and the using namespace that precedes it, which makes all names in the namespace available.

Such as:

Using namespace A

Using the using compilation directive in the global declaration area makes the name of the namespace available globally. In fact, we are already very familiar with this situation, because we have been using using namespace std.

We can also use the using compilation instruction in the function:

Int main () {using namespace A;} this is the end of the study on "how to use C++ 's using declaration and using compilation instructions". I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report