==10.cpp
#include
#include
#include "10.h"
using namespace std;
using namespace A_A;
extern void geta(A22&);
int AA::aa = 0;
AA::AA(char* ss)
{
strcpy(s,ss);
}
void A22::show() const
{
cout<<aa<<endl;
}
A22::A22(char* s,int sz,int ops,int pii,string na):AA(s),size(sz),name(na)
{
aa++;
this->pi = new int;
*pi = pii;
}
A22::~A22()
{
cout<<"析构调用"<<endl;
delete pi;
}
A22::A22(const A22& a):AA((char*)a.s),size(a.size)
{
aa++;
this->ops = a.ops;
this->pi = new int;
*pi = *(a.pi);
this->name = a.name;
}
void A22::get()
{
cout<<aa<<endl;
}
void A22::gets()
{
cout<<*pi<<endl;
cout<<name<<endl;
}
void test(int a,int b,int c=11)
{
cout<<c<<endl;
}
int main()
{
A22 a3("ioi",21,122,1024,"China");
A22 a4 = a3;
a4.gets();
}
====10.h头文件
#ifndef _10H
#define _10H
#include
#include
using namespace std;
namespace A_A
{
class AA
{
private:
protected:
char s[10];
public:
AA(char* ss);
static int aa;
};
class A22:public AA
{
public:
friend void geta(A22&);
void show() const;
A22(char*,int,int ops,int,string);
static void get();
void gets();
int ops;
A22(const A22& a);
virtual ~A22();
private:
const int size;
int * pi;
string name;
};
void geta(A22& a)
{
cout<<"name = "<<a.name<<endl;
}
}
#endif
=====101.cpp
#include
#include
#include "10.h"
using namespace std;
using namespace A_A;
extern class AA;
extern class A22;
extern void geta(A22&);
vc 6.0上编译显示:
--------------------Configuration: 10 - Win32 Debug--------------------
Compiling...
101.cpp
D:\wpwpw\c的测试的代码\101.cpp(7) : warning C4091: 'extern ' : ignored on left of 'class AA' when no variable is declared
D:\wpwpw\c的测试的代码\101.cpp(8) : warning C4091: 'extern ' : ignored on left of 'class A22' when no variable is declared
D:\wpwpw\c的测试的代码\101.cpp(9) : error C2872: 'A22' : ambiguous symbol
Error executing cl.exe.
Creating browse info file...
10.exe - 1 error(s), 2 warning(s)
---报错提示的是:
101.cpp文件中的
=====101.cpp
#include
#include
#include "10.h"
using namespace std;
using namespace A_A;
extern class AA;
extern class A22;
请问这是怎么回事啊?希望能详细的解释下,怎么去解决
都已经包含了头文件,头文件中有 geta 的定义,还有必要再去 extern 吗?
你的程序A22定义了两次,应该是重复包含造成的。
谁能帮我看看这道题
题目描述
查看题目信息
五一期间,Tom老师带领爱思创的同学去爬香山,香山的景色实在是太美了,他们想在一起拍个照片。现在将这些同学进行编号 (1~n),Tom老师要求队伍中的男生全部在左且需要按照身高从矮到高的顺序从左到右排,女生全部在右且需要按照身高从高到矮的顺序从左到右排。注意,身高一样的时候需要让编号小的在前,那么聪明的你能不能帮他们排一下队伍呢?
输入格式
第一行为总人数 n(2 <= n <= 40) (数据保证队伍中最少有一个男生和一个女生)
其后 n 行,每行数据包含一位同学的性别(男 male 或女 female )和身高(整数,单位:厘米),两个数据之间以空格分隔,每个同学的编号按照输入顺序编号为 1~n 。
输出格式
输出 n 行,每一行两个数据。
这两个数据分别表示按照要求排好队伍以后每位同学排队之前的编号以及身高,用空格分开。
样例输入
6
male 172
male 178
female 161
male 165
female 173
female 156
样例输出
4 165
1 172
2 178
5 173
3 161
6 156