Variables in array

Hi guys I have 1 question, when I was working in class I always used 1 variable seperetly but now I have array in private can u help me? what i must to do next in public?

class Cube{
private:
char Side[6]; //imagine CubexRube
public:

also I want to know what must to do in constructor

thanks
Hello @Dagr,

Well depends, if you need public access for this variable from outside;

What is the purpose of your class?
I want describe Cube class with sides like CubeOfRube 3x3 I want summon ready cube u know what I mean?
Sorry for the late reply;
Oh, yes, well i think that you should use integers (or doubles);

for example:

(This is to show my idea, not the best 'design')

1
2
3
4
5
6
7
8
class Cube
{
    private:
        int side;
    public:
        void setSide(const int& _side);
        int getSide() const;
};


yeah but I have char side[6] like this in private
Well to be honest i'm confused; But i can figure out something like this:


Side 1 : ?
Side 2 : ?
Side 3 : ?
Side 4 : ?
Side 5 : ?
Side 6 : ?


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
39
#include <iostream>

class Cube
{
    
    
private:
    char side[6];
    
    
public:
    Cube(const char& _value)
    {
        for(auto& s : side)
        {
            s = _value;
        }
    }
    
    //Not implemented yet
    void setSide(const char& _c,const int& _index);
    
    char getSide(const int& _index)
    {
        return side[_index];
    }
    
};

int main(int argc, const char * argv[])
{
    Cube a('?');
    int size = 6;
    for(int i = 0; i < size; ++i)
    {
        std::cout<<"Side " <<i+1 <<" : " <<a.getSide(i) <<'\n';
    }
    return 0;
}
deepest thanks to you bro
You are welcome @Dagr; But you could write more about your problem and how
this example helped to you for other people in the future with a similar problem!

:]

Topic archived. No new replies allowed.