Scope resolution opperator

Given the following method:

1
2
3
4
5
6
7
8
9
10
11
12
13
  void ToolsViewConsoleAbout_MainPage::updateBpaVerInfo()
  {
    m_bpaVerInfo = QLatin1String("");

    if (TJM::bpa().haveDevice())
    {
      m_bpaVerInfo = makeVersionString(TJM::bpa().firmwareVersion(),
                                       TJM::bpa().protocolVersion(),
                                       TJM::bpa().haveCompatibleDevice());
    }

    retranslateDeviceInfo();
  }


where the name of the program is: ToolsViewConsoleAbout_MainPage

I am trying to figure out what exactly the :: is doing. Is it nessasary? Could the method just be:


1
2
3
4
5
6
7
8
9
10
11
12
13
  void updateBpaVerInfo()
  {
    m_bpaVerInfo = QLatin1String("");

    if (TJM::bpa().haveDevice())
    {
      m_bpaVerInfo = makeVersionString(TJM::bpa().firmwareVersion(),
                                       TJM::bpa().protocolVersion(),
                                       TJM::bpa().haveCompatibleDevice());
    }

    retranslateDeviceInfo();
  }



where the name of the program is: ToolsViewConsoleAbout_MainPage
^^ this is not important. unless you did something screwy with argv[0] or hard coded something odd, the program is actually unaware of the name of its own executable / project name / file names (apart from #includes of course).

what you are seeing is the CLASS name.
it is usually necessary.

class ex
{
int x;
void foo() //does not need :: as it is inside the class
{x = 3;}
void bar();
}

void ex::bar() //needed. if you don't put ex::, the compiler can't tell that you did not INTEND
to have a stand-alone function named bar. And you can overload bar to have a stand-alone version. the :: is required.
{
x = 4;
}

that is:
void bar() //this function is not a class method. its a 'procedural design paradigm' free floating function. the only difference is the qualifier...
{
}
Last edited on
To be clear I think you are saying that.

void ex::bar(){} indicates to the compiler that bar() is a function of the class ex where

void bar(){} is just some random function called bar, is that correct?
exactly!
Topic archived. No new replies allowed.