In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "C++ class preliminary constant member function and constructor initial value list analysis", the explanation content in the article is simple and clear, easy to learn and understand, please follow the small series of ideas slowly in-depth, together to study and learn "C++ class preliminary constant member function and constructor initial value list analysis" bar!
header file mycpp.h
#include
classSales_data{
//friend function range declaration
friendstd::istream&read(std::istream&is,Sales_data&item);
friendstd::ostream&print(std::ostream&os,Sales_data&item);
public:
//constructor overrides built-in initialization values,: to {represents a list used to initialize member variables, called constructor initializer list
Sales_data(conststd::string&s="",constunsignedn=0,
constdoublep=0.0):bookNo(s),units_sold(n),revenue(p*n){};
//object is a constant, return must be a const, for example: instantiate a constant object constSales_dataconst_item;
std::stringisbn()const;
//Add a Sales_data object to another Sales_data object
Sales_data&combine(constSales_data&);
//Find the average price of the book sold
doubleavg_price()const;
private:
//built-in initialization is an empty string, because it is not a basic type, pointer and reference.
std::stringbookNo;//Basic type, built-in initialization undefined
unsignedintunits_sold;
doublerevenue;};
//declaration of a friend function; note that the declaration in the inside only indicates a range, indicating that the friend function can access objects of this class
std::istream&read(std::istream&is,Sales_data&item);
std::ostream&print(std::ostream&os,Sales_data&item);
Source file mycpp.cpp #include main function
intmain()//instantiate a constant object Thank you for reading, the above is the "C++ class preliminary constant member function and constructor initialization list analysis" content, after learning this article, I believe that we have a deeper understanding of the C++ class preliminary constant member function and constructor initialization list analysis, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.