static members

Class a
Class b

When i use a as a.static member of b i cannot access any of the method of class.a. Within b
Unresolved external
Post the code if you can that will help us to analyse
Apart from declaring a member static you have to define it outside the class. For example

1
2
3
4
5
6
struct A
{
   static int x; // it iis a declaration only
};

int A::x; // it is a definition 
How would you call method
static void setx(int n){x=n;}
If it is indeed a static method then you can call it by using two different methods. Let assume that this method belongs to class A and a is an object of class A. Then you can write either

A::setx( value );

or

a.setx( value );
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class A
{
public:
	static void setx(int n){x=n;}
private:
	static int x;
};

int A::x;

int main()
{
	A::setx(7);
}
Would a call to setx within the ctor of A change the value of x
A()
{
setx(2);
}
Yes, it will be changed.
Topic archived. No new replies allowed.