Questions tagged [scope-resolution]

72 questions
512
votes
9 answers

What is the meaning of prepended double colon "::"?

I found this line of a code in a class which I have to modify: ::Configuration * tmpCo = m_configurationDB;//pointer to current db and I don't know what exactly means the double colon prepended to the class name. Without that I would read:…
rmbianchi
  • 6,241
  • 6
  • 26
  • 27
94
votes
2 answers

vim does not find and replace simple phrase that is clearly present

I have a simple vim problem that Google hasn't managed to help me with. Any thoughts are appreciated. I do the following search and replace: :s/numnodes/numnodes1/g On a file containing the following text: numprocs=0 numnodes=0 I get E486:…
Mark C.
  • 1,773
  • 2
  • 16
  • 26
66
votes
2 answers

What does C++ syntax “A::B:A {};” mean

What does C++ syntax struct A::B:A {}; mean? Where is this name definition (or access) described in the C++ standard? #include struct B; struct A { struct B; }; struct A::B:A { }; int main() { A::B::A::B b; …
devsh
  • 549
  • 1
  • 4
  • 7
42
votes
7 answers

Why does C++ need the scope resolution operator?

(I know what the scope resolution operator does, and how and when to use it.) Why does C++ have the :: operator, instead of using the . operator for this purpose? Java doesn't have a separate operator, and works fine. Is there some difference…
Karu
  • 4,512
  • 4
  • 30
  • 31
16
votes
2 answers

In C++, what is the scope resolution ("order of precedence") for shadowed variable names?

In C++, what is the scope resolution ("order of precedence") for shadowed variable names? I can't seem to find a concise answer online. For example: #include int shadowed = 1; struct Foo { Foo() : shadowed(2) {} void bar(int…
Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
15
votes
3 answers

whats the difference between dot operator and scope resolution operator

I just wanted to know the difference between . operator and :: operator?
defiant
  • 3,161
  • 11
  • 41
  • 65
14
votes
1 answer

C++0x decltype and the scope resolution operator

With a class such as Foo: struct Foo { static const int i = 9; }; I find that GCC 4.5 will reject the following Foo f; int x = decltype(f)::i; It will work if I use an intermediate typedef, such as: typedef decltype(f) ftype; int x =…
user2023370
  • 10,488
  • 6
  • 50
  • 83
14
votes
4 answers

What does the "::" mean in "::tolower"?

I've seen code like this: std::string str = "wHatEver"; std::transform(str.begin(), str.end(), str.begin(), ::tolower); And I have a question: what does mean :: before tolower? and std::tolower not works, but ::tolower works OK
VextoR
  • 5,087
  • 22
  • 74
  • 109
11
votes
4 answers

Difference between this->field and Class::field?

I'm wondering something in C++. Admitting the following code: int bar; class Foo { public: Foo(); private: int bar; }; Inside my class, is there any difference between this->bar and Foo::bar? Are there cases where one is invalid?
Bryan Peeters
  • 161
  • 10
11
votes
2 answers

What does ::new mean?

When examining the MS directX 11 DXUT example, the following code appeared: template HRESULT CGrowableArray ::SetSize( int nNewMaxSize ) { int nOldSize = m_nSize; if( nOldSize > nNewMaxSize ) { assert( m_pData ); if(…
Lycoress
  • 113
  • 1
  • 7
10
votes
2 answers

Using fully qualified name for std namespace in C++

If name in C++ is not fully qualified, e.g. std::cout, it can lead to an unintentional error, such as mentioned at https://en.cppreference.com/w/cpp/language/qualified_lookup. But using a fully qualified name for ::std namespace, e.q. ::std::cout,…
Kam
  • 211
  • 1
  • 8
9
votes
2 answers

template method and default template argument

My problem can be resumed by the following piece of code: template struct C2; template struct C1 { template class Container = C2> void m() {} }; template
lrleon
  • 2,610
  • 3
  • 25
  • 38
9
votes
1 answer

C++ global namespace access from within another namespace

In the C++ code below, foobar is defined first for a single double parameter, and then again for a single parameter of type Foo. Both are defined within the global namespace. Within the one namespace, a further overload of foobar is defined, with a…
user2023370
  • 10,488
  • 6
  • 50
  • 83
8
votes
1 answer

:: scope resolution operator in front of a template function call in c++

I'm stuck with templates and scope resolution operator. I found these line in a file, I'm not able to figure out why we are using :: in front of a template function call, as of my knowledge we can only use :: in front of variables when refering to a…
Vikram Singh
  • 273
  • 1
  • 3
  • 10
8
votes
7 answers

What is the purpose of "::delete" in C++?

I'm currently looking at C++ code that uses ::delete to delete a pointer. A meaningless example of this is: void DoWork(ExampleClass* ptr) { ::delete ptr; } What is the purpose of using the delete keyword in this way?
Bryan Muscedere
  • 572
  • 2
  • 10
  • 23
1
2 3 4 5