i want my data can be used over every function, so i need a class to capture them, am i correct??

here is my outline, im not sure if i use it correctly, please help!!

class CLASS
{
private:
        int * (something)
        string * (something)                          
public:
        void (function) ()
};

void CLASS::(function)
{
}

int main()
{
int * (something)
string * (something)
(something) = new int[size]
(something) = new string[size]
}

i want my data can be used over every function, so i need a class to capture them, am i correct??

here is my outline, im not sure if i use it correctly, please help!!

class CLASS
{
private:
        int * (something)
        string * (something)                          
public:
        void (function) ()
};

void CLASS::(function)
{
}

int main()
{
int * (something)
string * (something)
(something) = new int[size]
(something) = new string[size]
}

There are three problems.

In your main() you're declaring int* and string*, but those are already declared in your class. Remove those two lines.

Second, you have your int* and string* in your class listed as private, which means you will not be able to access them (You will get a compiler error saying private variable not available). So you have to make them public (or use public functions to do the allocating for you, then call those functions (which is generally the most "accepted" coding method).

Third (and you may have just forgotten this)... in your main() you must first instantiate a class variable, and then use the "." operator to refer to variables inside that class. For example, in main you would write:

CLASS test;
test.something = new int;


-Greywolf

use public functions to do the allocating for you, then call those functions (which is generally the most "accepted" coding method

how to do this??

CLASS test;
test.something = new int;

what is test stand for??

for second: my program is asked to set every variable private... so how to access them?

for third: i have tried to instantiate the class, but this time it makes my functions cannot work properly, anything can do to the functions? or i should also instantiate the class in my functions??

for second: my program is asked to set every variable private... so how to access them?

for third: i have tried to instantiate the class, but this time it makes my functions cannot work properly, anything can do to the functions? or i should also instantiate the class in my functions??

Use this example to write your own. Study it to see how it works:

class test{

private:

  int* number_array;

public:

  int* get_array(){
    return number_array;
  }

  void allocate_array(int size){
    number_array = new int[size];
  }

};

int main(){
  test A;
  A.allocate_array(10);
  A.get_array()[0] = 3;
  A.get_array()[1] = 5;


  cout << A.get_array()[0] << endl;
  cout << A.get_array()[1] << endl;

  system("pause");
  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.