Access static variable from another class in another file

How do I access a variable found in another class in a different file.
This is my attempt but it does not compile. Might have some syntax error. Just need the logic. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
Test.h
#ifndef TEST_H
#define TEST_H
class Test
{
public:
	Test();
	virtual ~Test();

	//create a static variable e.g. static int var;
       static int var;
};
#endif /*TEST_H*/ 


1
2
3
4
5
6
7
8
9
10
CLA.h
#ifndef CLA_H
#define CLA_H
class CLA
{
public:
	CLA();
	virtual ~CLA();
};
#endif /*CLA_H*/ 


1
2
3
4
5
6
7
8
9
10
11
CLA.cpp
#include "CLA.h"
#include <iostream>
#include <Test.h>
CLA::CLA(){}
CLA::~CLA{}
CLA::join(){
	Test jn;
	std::cout << Test.var << std::endl; //Does not compile
        // I need this Test.var to be 1
}


1
2
3
4
5
6
main.cpp
#include <Test.h>
int main(){
	Test pt;
	pt.var = 1;	
}



1
2
3
4
5
6
7
#include <Test.h>

int main()
{
    Test::var = 1;
    return 0;
}
Topic archived. No new replies allowed.