Hi guys,
I'm taking a OOP course in the university and we're studying CPP, so I'm quite new at OOP.
I've tried to solve a small problem which was given to students in 2007 and I've came across a problem:
The Visual Studio doesn't recognize the word "string". At the lecture we were told this is a saved word(and in order to use it I have to include the "string" library, so I did). I've added to code so you could look at it.
If it wasn't clear so far, I'm using Visual Studio 2012 Ultimate.
Thanks in advance!
1 2 3 4 5 6 7 8 9
#include <iostream>
#include <string>
class Person{
private:
int age;
string _pname;
string _last_name;
}
Because standard C++ classes are declared in the standard namespace std.
Consider an example with your own namespace
1 2 3 4 5 6 7 8 9 10
namespace MyNamespace
{
class Person {};
}
int main()
{
Person p1; // Error. There is no such name as Person
MyNamespace::Person p2; // O'k there is such name in your namespace
}
7.3 Namespaces [basic.namespace]
1 A namespace is an optionally-named declarative region. The name of a namespace can be used to access entities declared in that namespace; that is, the members of the namespace. Unlike other declarative regions, the definition of a namespace can be split over several parts of one or more translation units.
2 The outermost declarative region of a translation unit is a namespace; see 3.3.6.
3.3.6 Namespace scope
2 A namespace member can also be referred to after the :: scope resolution operator (5.1) applied to the name of its namespace or the name of a namespace which nominates the member’s namespace in a using-directive;
see 3.4.3.2.
3 The outermost declarative region of a translation unit is also a namespace, called the global namespace. A name declared in the global namespace has global namespace scope (also called global scope). The potential scope of such a name begins at its point of declaration (3.3.2) and ends at the end of the translation unit that is its declarative region. Names with global namespace scope are said to be global name.