| |

VerySource

 Forgot password?
 Register
Search
View: 577|Reply: 4

Help look at the error

[Copy link]

3

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-7 13:30:02
| Show all posts |Read mode
#include <iostream.h>
class {
private:
static int x;
};
void func (int a)
{x = a;}

Where is wrong, how to change it, explain it, thank you
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-1-7 23:54:01
| Show all posts
#include <iostream.h>
class {// Give a class name
private:
static int x;
};
void func (int a)
{x = a;} // Do you want to use x in the class? Then don't use private, and if you want to get members in the class, add A ::
To the following
#include <iostream.h>
class A {
public:
static int x;
};
void func (int a)
{A :: x = a;}
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-8 02:45:01
| Show all posts
#include <iostream.h>
class ?? {
private:
static int x;
};
void func (int a)
{??. x = a;}

To add a class name
Static variables are accessed using the class name ::. X
Reply

Use magic Report

1

Threads

19

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-8 09:27:01
| Show all posts
Upstairs solution
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-11 17:27:01
| Show all posts
There is no class name, and the x used in the function is not specified, of course it is wrong
Most likely you want to use the x in the class, I understand so
Should be like this /
#include <iostream.h>
class classname / * Give a class name * / {
private:
static int x;
};
int classname :: x; // outside the class defines the static variables of the class, what is inside the class is just a declaration
void fun (ing a)
{x = a;}
that's it!!!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list