#ifndef CHARACTER_H #define CHARACTER_H class Character { private: }; static unsigned max_x; static unsigned max_y; unsigned x, y_; //where the character is located public: static void setLimits (unsigned w, unsigned h); Character(); Character (unsigned x, unsigned y); //to return the coordinates of location_ std::string to_string() const; //mutators void setLocation (unsigned x, unsigned y); void moveLeft(); void moveRight(); void moveUp(); void moveDown(); #endif

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Hi I need help please I dont understand what static means on a C++ class member. I dont understand what it is I will provide an example. In the example the static data members are max_x, and max_y

 

1 #ifndef CHARACTER_H
2 #define CHARACTER_H
3
4 class Character {
5
6
7
8
9
_0
1
_2
.3
4
5
6
_7
_8
_9
20
1
2
-3
24
5
6
};
private:
static unsigned max_x;
static unsigned max_y;
unsigned x, y_; //where the character is located
public:
static void setLimits (unsigned w, unsigned h);
Character();
Character (unsigned x, unsigned y);
//to return the coordinates of location_
std::string to_string() const;
//mutators
void setLocation (unsigned x, unsigned y);
void moveLeft();
void moveRight();
void moveUp();
void moveDown();
#endif
Transcribed Image Text:1 #ifndef CHARACTER_H 2 #define CHARACTER_H 3 4 class Character { 5 6 7 8 9 _0 1 _2 .3 4 5 6 _7 _8 _9 20 1 2 -3 24 5 6 }; private: static unsigned max_x; static unsigned max_y; unsigned x, y_; //where the character is located public: static void setLimits (unsigned w, unsigned h); Character(); Character (unsigned x, unsigned y); //to return the coordinates of location_ std::string to_string() const; //mutators void setLocation (unsigned x, unsigned y); void moveLeft(); void moveRight(); void moveUp(); void moveDown(); #endif
Expert Solution
Static class member

1) We can define class members static using static keyword.

2) When we declare a member of a class as static it means no matter how many objects of the class are created, there is only one copy of the static member.

3) A static member is shared by all objects of the class.

4) All static data is initialized to zero when the first object is created, if no other initialization is present. 

5) It is visible only within the class, but its lifetime is the entire program

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY