xiaohua417527013 2014-12-22 09:13 采纳率: 0%
浏览 1985

刚入门学习c++,出现了问题,各位高手来帮帮忙,谢谢

==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;

extern void geta(A22&);------这行提示错误


请问这是怎么回事啊?希望能详细的解释下,怎么去解决

  • 写回答

3条回答 默认 最新

  • 91program 博客专家认证 2014-12-22 09:56
    关注

    都已经包含了头文件,头文件中有 geta 的定义,还有必要再去 extern 吗?

    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的