about global scope

(correct me if i mistake)
the Global Scope is for create and initializate variables, create functions\class's\namespaces and more... i understand that.
(sorry if my question is confuse.... but i'm trying work with my english :()
when we build a class with some variables, is there any way, on Global Scope, that we can change the variables values with object name?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname

class test
{
    public:
    event(Soma,(int a,int b)) ;
    event(hello);
    void write(string a)
    {
        Console.write(a);
        Soma(2,3);
    }
};

test a;
//
int a.Soma = [](int a, int b)
{
    COORD v={10,10};
    Console.SetCaretPosition(v);
    Console.SetColorAndBackground(ForeColorRed,0,true);
    Console.write("\nMessage Printed\n" ,a+b , "\n") ;
    return 0;
}

(console is my class for work with console)
like you see i'm trying changing the Soma value on Global Scope... i'm geting errors. my question is: is there anyway for validate that for don't get errors?

erro message:

'error: expected initializer before '.' token'

without a return type:
'error: 'a' does not name a type'

please i'm trying, several time, fix these code without sucess :(
No, you can't do that. You can declare a global variable, but you can't run executable code at the file scope.

if i use a static variable, i must use the class name and not the object name, right?
If it's a static data member, then yes. The member is, effectively, shared between all instances of the class. It's not owned by any one object.
so can you advice me something instead 'it's no possible'?
(sorry bored you with these, but i realy need it)
You can have global objects like your a-object, but you still have to change the value within some function (or other scope).
bad the C++ don't let overload the '::' operator ;)
thanks for all to all
Topic archived. No new replies allowed.