In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 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.
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.