namespace myNum
{
int x = 105;
}
int main()
{
bool isFlag = false;
if(myNum::x % 2 == 0)
{
isFlag = false;
}
else
{
isFlag = true;
}
if(isFlag)
{
cout << myNum::x << "是奇数"<< endl;
}
else
{
cout << myNum::x << "是偶数"<< endl;
}
return 0;
}
{
int x = 105;
}
int main()
{
bool isFlag = false;
if(myNum::x % 2 == 0)
{
isFlag = false;
}
else
{
isFlag = true;
}
if(isFlag)
{
cout << myNum::x << "是奇数"<< endl;
}
else
{
cout << myNum::x << "是偶数"<< endl;
}
return 0;
}
int main(void) {
cout << A::x << endl;
B::f1();
system("pause");
return 0;
}
}
cout << A::x << endl;
B::f1();
system("pause");
return 0;
}
}
2017-08-08
#include <iostream>
#include <stdlib.h>
using namespace std;
namespace A {
int x = 0;
void f1() {
cout << "A" << endl;
}
void f2() {
cout << "B" << endl;
}
namespace B {
int x = 2;
void f1() {
cout << "A" << endl;
}
void f3() {
cout << "C" << endl;
}
}
请问这个错哪?
#include <stdlib.h>
using namespace std;
namespace A {
int x = 0;
void f1() {
cout << "A" << endl;
}
void f2() {
cout << "B" << endl;
}
namespace B {
int x = 2;
void f1() {
cout << "A" << endl;
}
void f3() {
cout << "C" << endl;
}
}
请问这个错哪?
2017-08-08
刚发现C++命名空间得定义了才能使用。之前我把using namespace B;放在B定义前,结果编译的时候报错
g++ first.cpp -o first
first.cpp:4:17: error: ‘B’ is not a namespace-name using namespace B;
first.cpp:4:18: error: expected namespace-name before ‘;’ token using namespace B;
(字数限制,剩下的贴不上来了)
g++ first.cpp -o first
first.cpp:4:17: error: ‘B’ is not a namespace-name using namespace B;
first.cpp:4:18: error: expected namespace-name before ‘;’ token using namespace B;
(字数限制,剩下的贴不上来了)
2017-08-05
namespace myNum
{
int x = 105;
}
int main()
{
bool isOdd = false;
if(myNum::x % 2 == 0)
{
isOdd=false;
}
else
{
isOdd=true;
}
if(isOdd)
{
cout<<"变量"<<myNum::x<<"是奇数"<<endl;
}
else
{
cout<<"变量"<<myNum::x<<"是偶数"<<endl;
{
int x = 105;
}
int main()
{
bool isOdd = false;
if(myNum::x % 2 == 0)
{
isOdd=false;
}
else
{
isOdd=true;
}
if(isOdd)
{
cout<<"变量"<<myNum::x<<"是奇数"<<endl;
}
else
{
cout<<"变量"<<myNum::x<<"是偶数"<<endl;