.
.
, , , .
, .
using .
using namespace ,
, . using. , .
#include <iostream>
using namespace std;
namespace NAME
{ int n1=1;
int n2=2;
}
// int n1; main n1
int main()
{ NAME::n1=3;
// n1=3; // error 'n1': undeclared identifier
// n2=4; // error 'n2': undeclared identifier
using namespace NAME; // n1 n2
n2=4;
cout << n1 <<" "<< n2 << endl; // 3 4
{ n1=5;
n2=6;
cout << n1 <<" "<< n2 << endl; // 5 6
}
return 0;
}
:
3 4
5 6
using ,
, .
,
, .
, .
#include <iostream>
using namespace std;
-
/ iostream . namespace std. using, , . , -
. , Microsoft .h, .. #include <iostream.h> Visual C++ 7.1 .
using .
using :: , . using -
( ) ().
#include <iostream>
using namespace std;
namespace NAME
{ int n1=1;
int n2=2;
}
int main()
{ NAME::n1=3;
// n1=4; error 'n1' NAME::n1
// n2=5; error 'n2': undeclared identifier
// int n2;
using NAME::n2; // n2
|
|
n2=6;
cout <<NAME::n1<<" "<< n2 << endl; // 3 6
{ NAME::n1=7;
n2=8;
cout <<NAME::n1<<" "<< n2 << endl;// 7 8
}
return 0;
}
:
3 6
7 8
using -
. n2 , n1 . using , . , . () , ( ), .
. , , , delete, , . , . , . , ,
.
class Shape
{protected:
double s;
public:
Shape(char *fig): s(0)
{ cout << " Shape ( "<< fig <<')'<< endl;}
virtual ~Shape()
{ cout << " Shape " << endl;}
void virtual print()
{cout<<s<<endl;}
void virtual area()=0;
};
class Circle: public Shape
{ int r;
public:
Circle(char *name,int r): Shape(name)
{ cout << " Circle "<<endl;
this->r=r;
}
~Circle()
{ cout << " Circle " << endl;}
void area();
};
void Circle::area()
{ s=r*r*3.14; cout<<" = "; this->print();
}
int main()
{ Shape *fg1;
fg1=new Circle("(" ",2); fg1->area(); delete fg1; return 0;
}
,
, .. (,
).
,
, .
.