see these class:

class test
{
   public:
       void Created(){};
       test()
       {
           Created();
       }
};

now we can create objects from it. ok.
but can i overloading the scope-resolution ('::') for the object accept and change the Created() function?

Recommended Answers

All 10 Replies

No you can not overload ::. Why would you want to?

for change the functions(with diferente objects) outside of functions\class and others.

(in my case) the problem of class direved from other class is that i must re-declare the functions

You'd have to redeclare the function even if you could overload ::, so what's the problem?

class test
{
   public:
       virtual void Created() {cout << "Hello from test class\n";}
       test()
       {
           Created();
       }
};

class Child : public text
{
public:

   virtual void Created() {cout << "Hello from Child\n";}
 };

 int main()
 {
     Child c;
     c.Created();  // call Created in Child class
     c.test::Created(); // call Created in test class
 }

some day ago i read something, so please correct me.
i understand that i can't use a varname outside the functions\class's with '::' operator, but seems that i can use with static functions, can you explain please?

Can you post an example of the situation you're asking about?

i understand that i can't use a varname outside the functions\class's with '::' operator

Make the variable static and you can use it outside the class with :: opertor.

class MyClass
{
public:
   static int x;
 };

int MyClass::x = 0; // static variables must also be declared like globals

int main()
{
    MyClass::x = 1;
}

the same for functions, right?

Functions are coded as normal.

class MyClass
{
public:
   static int x;
   static int foo();
 };

int MyClass::x = 0; // static variables must also be declared like globals
int MyClass::fo()
{
    return x;
}

int main()
{
    MyClass::x = 1;
}

thanks...
for finish: can i do object polymorphism and use '::' operator?

Not that I know of.

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.