Skip to main content
deleted 112 characters in body
Source Link
Pow
  • 414
  • 1
  • 12

The mainonly difference between a class and a struct is that members within a struct are automatically public. Also, classes can be inherited from, see Polymorphism in c++

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

but a struct would also work, e.g.

struct Input
{
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

The more important part is that they are static, since that would mean modifying them anywhere would change the values everywhere. Similar to global variables, also see Static keyword in c++.

The main difference between this and your method is that they are no longer global, but they do essentially the same thing. Instead of grabbing them normally, you would use something like Input::isMainLoopActive. This can also help code become more clean and understandable, as anyone can see its part of input, but thats just an example, you can change it to work with your scripts, and create multiple structs/classes if you need.

The main difference between a class and a struct is that members within a struct are automatically public. Also, classes can be inherited from, see Polymorphism in c++

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

but a struct would also work, e.g.

struct Input
{
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

The more important part is that they are static, since that would mean modifying them anywhere would change the values everywhere. Similar to global variables, also see Static keyword in c++.

The main difference between this and your method is that they are no longer global, but they do essentially the same thing. Instead of grabbing them normally, you would use something like Input::isMainLoopActive. This can also help code become more clean and understandable, as anyone can see its part of input, but thats just an example, you can change it to work with your scripts, and create multiple structs/classes if you need.

The only difference between a class and a struct is that members within a struct are automatically public.

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

but a struct would also work, e.g.

struct Input
{
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

The more important part is that they are static, since that would mean modifying them anywhere would change the values everywhere. Similar to global variables, also see Static keyword in c++.

The main difference between this and your method is that they are no longer global, but they do essentially the same thing. Instead of grabbing them normally, you would use something like Input::isMainLoopActive. This can also help code become more clean and understandable, as anyone can see its part of input, but thats just an example, you can change it to work with your scripts, and create multiple structs/classes if you need.

Update-made easier to understand
Source Link
Pow
  • 414
  • 1
  • 12

The main difference between a class and a struct is that members within a struct are automatically public. Also, classes can be inherited from, see Polymorphism in c++

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

then anywhere you can access thembut a struct would also work, e.g. input.isMainLoopActive

struct Input
{
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

Edit: I slightly missunderstood the questionThe more important part is that they are static, but you could still use thissince that would mean modifying them anywhere would change the values everywhere.

Edit 2: Im no c++ guru so this may be completely wrong Similar to global variables, also see Static keyword in c++.

The main difference between a classthis and a structyour method is that members within a structthey are automatically publicno longer global, but they do essentially the same thing. Instead of grabbing them normally, you would use something like Input::isMainLoopActive. This can also help code become more clean and understandable, as anyone can see its part of input, but thats just an example, you can change it to work with your scripts, and create multiple structs/classes if you need.

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

then anywhere you can access them e.g. input.isMainLoopActive

Edit: I slightly missunderstood the question, but you could still use this.

Edit 2: Im no c++ guru so this may be completely wrong.

The main difference between a class and a struct is that members within a struct are automatically public.

The main difference between a class and a struct is that members within a struct are automatically public. Also, classes can be inherited from, see Polymorphism in c++

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

but a struct would also work, e.g.

struct Input
{
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

The more important part is that they are static, since that would mean modifying them anywhere would change the values everywhere. Similar to global variables, also see Static keyword in c++.

The main difference between this and your method is that they are no longer global, but they do essentially the same thing. Instead of grabbing them normally, you would use something like Input::isMainLoopActive. This can also help code become more clean and understandable, as anyone can see its part of input, but thats just an example, you can change it to work with your scripts, and create multiple structs/classes if you need.

added 110 characters in body
Source Link
Pow
  • 414
  • 1
  • 12

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

then anywhere you can access them e.g. input.isMainLoopActive

Edit: I slightly missunderstood the question, but you could still use this.

Edit 2: Im no c++ guru so this may be completely wrong.

The main difference between a class and a struct is that members within a struct are automatically public.

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

then anywhere you can access them e.g. input.isMainLoopActive

Edit: I slightly missunderstood the question, but you could still use this.

Edit 2: Im no c++ guru so this may be completely wrong.

You could just create a class for all the input:

class Input
{
public:
    static bool isMainLoopActive;
    static bool isMoveRightPressed;
    ...
}

then anywhere you can access them e.g. input.isMainLoopActive

Edit: I slightly missunderstood the question, but you could still use this.

Edit 2: Im no c++ guru so this may be completely wrong.

The main difference between a class and a struct is that members within a struct are automatically public.

Post Undeleted by Pow
Post Deleted by Pow
Source Link
Pow
  • 414
  • 1
  • 12
Loading