-
Although both car and bus inherit from the same parent class, extending them separately can result in rich and different subclasses, such as adding a weight member variable as you said, and the member variables of the two subclasses are irrelevant. call, for example:
car g_car;
bus g_bus;
g_;g_;
Suppose getweight returns the weight of the car, then the car returns its own weight, and the bus returns the weight of the bus, and the two have nothing to do with each other.
In addition, you can add other member variables or functions to the two subclasses to suit your needs.
-
Each class can have its own members, which can have the same name, and is a matter of scope.
-
You don't know much about object-oriented programming yet! It is recommended to read more books! Write more and practice more!
Each class has its own members (variables. functions) and do not affect each other! Can have the same name!
When using objects of different classes, you can use this variable correctly! Of course, if you set it to private, you can't use it externally! Can only be used in this category!
-
You have to understand the problem with C++ namespace.
Two classes can have the same data members and functions. Both. The class names themselves make up their respective namespaces.
Other than that. namespace a
class ca
namespace b
class cb
It is also permissible.
Summary: You should take a good look at the class and namespace definitions in C++.
-
Two variables with the same name will be distinguished according to the different scopes...
-
Scope and namespace.
-
The short, int, long, and long long types use different numbers of bits to store values (you know the concept of bits for yourself) and can represent up to 4 different integer widths. C++ provides a flexible standard segment that ensures a minimum length (borrowed from C) as follows:
1.short at least 16 bits.
2.The int is at least as long as the short.
3.long is at least 32 bits and at least as long as int.
-
A reference type is really an alias.
For example, int a = 0;
int& b = a;
Using B is equivalent to using A.
Personally, I think there is a reference call to a function.
It is also possible that some variables have difficult names to remember, but they cannot be changed, so they give them an easy alias.
-
Static variables, which are initialized only once. So here b is defined only once.
So 1 will be occupied, but very little. It's pretty much the same as the global variable definition.2 No, because there are no multiple definitions, only one definition.
3 Aside from the life cycle, the biggest difference is the scope.
Local variables can only be accessed within a function, while global variables can be accessed by anyone, which can easily lead to confusion, especially in the case of multithreading.
In addition, non-static local variables are released after the function exits, and if all variables are defined as global, it is obviously a waste of memory.
-
Function: It is a set of operations, such as eating, it can be eating rice, it can be eating noodles, you can eat a bowl, you can also eat half a bowl, there are different ways to eat different things to eat, this content is the parameter of the function, and different operations are performed by judging the different parameters.
A variable is a container that records a certain data, such as a bowl, which can indicate that there is half a bowl of rice or a bowl of rice left in the bowl through the difference in variable values, or you can add half a bowl of rice to this bowl by calculating the variable.
It's very abstract to say, and it's not as fast as learning the program directly.
-
Variables are used to store data, while functions are used to process data.
-
For example, y=x*2;That's the function.
Among them, cai, x y are all variables.
-
Upstairs, it's mixed upstairs.,for,while, although I don't know C++,But I also know that it's a loop statement.,Not a definition variable.。
-
You have to have a header file first, and then type for , while, and that's it.
-
I remember that it was in the book, and I checked it for you in the evening, and now I'm at work.
-
It's more practical for you to look up online or buy books.
If the assignment is equal to 0, it is true, and if it is not equal to 0, it is false.
In fact, this is a simple question of variable type and variable function, I think it should be explained like this: first, the original purpose of variable definition is to use the variable we define to meet the needs of our program, so, above you define variable a, then later, you will use this variable to do some operations, in most cases, it is to be initialized, so, give a corresponding type of value to initialize the variable, so that some operations can be used in the future, second, the understanding of that sentence:" You want a to represent 5, so you want to assign the value of a to 5", in fact, it is an initialization process of the variable a, where a is int (integer), corresponding to an initial value of 5, which is expressed like this: >>>More
A local variable (an internal variable) is defined inside a function, and its scope is limited to the variable inside the function that defines it. >>>More
Absolutely. The reason why it is a variable is that its value can be changed all the time, so that it can be called a variable. >>>More
Friend, let me tell you what's good, the version you're using and this M2 is blue, it's not the same at all, and I think you put the horse's head on the cow's body, and it must be a little inappropriate. >>>More