Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Non-local class, namespace scope, function name must be unqualified.

Posted on 2013-01-24
3
Medium Priority
?
503 Views
Last Modified: 2013-01-24
Hello Experts!

Found such a description and I do not really understand it...

However, you can define a function in a friend declaration. The class must be a non-local class. The function must have namespace scope, and the function name must be unqualified. The following example demonstrates this:

1. what is non-local class?
2. The function must have namespace scope- what does it mean?
3. Function name must be unqualified- what does it mean?


class A {
  void g();
};

void z() {
  class B {
    friend void f() { }; // error
  };
}

class C {
  friend void A::g() { } // error
  friend void h() { }
};

Open in new window



Thank you!
0
Comment
Question by:panJames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 38813560
1. what is non-local class?

A class declared inside a function or method is non-local. It can not be used outside the defining scope.
0
 
LVL 22

Expert Comment

by:ambience
ID: 38813574
3. Function name must be unqualified?

These are qualified function names

  friend void ::h() {
  }
  friend void Test::h() {
  }

This is not

  friend void h() {
  }

WRT - friends that this means is

void f() {}

namespace Test {

      void f() {}

      class C
      {
                // definition must be unqualified
            friend void h() {
                  cout << "From h" << std::endl;
            }
            friend void Test::f(); // qualified declaration is allowed
            friend void ::f(); // qualified declaration is allowed

      public:
            void method()
            {
                  h();
            }
      };

}
0
 
LVL 22

Accepted Solution

by:
ambience earned 2000 total points
ID: 38813594
2. The function must have namespace scope- what does it mean?

This should explain

namespace Test {

	void h();  // h is declared in namespace - not defined!

	class C 
	{
	public:
                // this is inside C but its definition of h in the namespace's scope
		friend void h() { 
			cout << "From h" << std::endl;
		}
	};

}


int main() 
{
	Test::h();
}

Open in new window

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question