@YFGHNG many thanks for showing me that keyword. I just learned something new.
@mutexe, yes i know i didn't create an object o type B for example purposes.
I gave that simple example to explain what i needed. Perhaps it was too simple. I will try to give a more elaborated one:
I want to have a class that gathers and stores information about all hard drives present in the system, (classA). On classB i want to be able to access the classA's struct values and change it if needed and on main(), i want to "read" classA's struct values wether or not those values were changed on classB.
My real problem is how i can share values from a class to others classes and not with the code it self. I apologize for not using real code in the functions because i am using qt framework and don't really know how to not use it to get an hard drive list and it is not my goal to know it, for now.
With all this in mind i'm using a struct array like.
1 2 3 4
|
struct hardDiskStruct{
string driveName, driveFileSystemType, state;
int spaceFree;
};
|
This struct will be used on class A.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
// for the sake of this example i hardcoded 3hdd
hardDiskStruct hardDiskList = new hardDiskStruct[3];
hardDiskStruct classA::get_hddList(){
int counter = 0;
// ... some c++ functions to retrieve current system's hdd
// please assume "localdrive" can read the needed hdd stuff.
foreach (localdrive){
hardDiskList[counter].driveName = locadrive(drive name)
hardDiskList[counter] driveFileSystemType = localdrive(drive filesystem type)
hardDiskList[counter].spaceFree = localdrive( free space available)
hardDiskList[counter].state = "free";
counter++;
}
return hardDiskList;
}
int main{
// i want to have access to classA hardDiskList array values
// to know which disks are available.
return 0;
}
classB{
// i want to have access to classA hardDiskList array values to know which disks
// are available and change the state to "busy" when needed.
}
|
After all this i read in the tutorials section about "static"! Could i use "static" keyword?
Please give me simple examples.