命名空间问题 [英] Namespace problem

查看:65
本文介绍了命名空间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题


在file1.h


名称空间A

{< br $>
class Bar

{

void foo();


};
< br $>
}

在file2.h


类酒吧;


类用户< br $>
{


Bar * pBar;


};

在file2.cpp


#include" file2.h"

#include" file1.h"


用户: :func()

{


pBar = new Bar;

pBar-> foo(); //链接器错误这里

}

如果我尝试在file2.h中转发声明这样的


class A :: Bar我得到一个编译错误,说A不是一个类或

命名空间

和MSVC ++ 8.


如何解决这个问题。

Hi, i have the following problem

In file1.h

namespace A
{
class Bar
{
void foo();

};

}
In file2.h

class Bar;

class User
{

Bar* pBar;

};
In file2.cpp

#include "file2.h"
#include "file1.h"

User::func()
{

pBar = new Bar;
pBar->foo(); // linker error here
}
If i try to forward declare in file2.h like this

class A::Bar i get a compiler error saying that A is not a class or
namespace
with MSVC++8.

How to solve this issue.

推荐答案

tech写道:
tech wrote:

我有以下问题


在file1.h


名称空间A

{

class酒吧

{

void foo();


};


}


在file2.h


类酒吧;


类用户

{


Bar * pBar;


};


在file2.cpp中


#include" file2.h"

#include" file1.h"


用户: :func()

{


pBar = new Bar;

pBar-> foo(); //链接器错误这里

}


如果我尝试在file2.h中转发声明这样的


class A :: Bar我得到一个编译器错误,说A不是一个类或

命名空间

和MSVC ++ 8.


如何解决这个问题。

Hi, i have the following problem

In file1.h

namespace A
{
class Bar
{
void foo();

};

}
In file2.h

class Bar;

class User
{

Bar* pBar;

};
In file2.cpp

#include "file2.h"
#include "file1.h"

User::func()
{

pBar = new Bar;
pBar->foo(); // linker error here
}
If i try to forward declare in file2.h like this

class A::Bar i get a compiler error saying that A is not a class or
namespace
with MSVC++8.

How to solve this issue.



我认为你必须重新打开命名空间:


命名空间A {

class Bar;

}


class User {

A :: Bar * pBar;

}


br,

Martin

I think you have to reopen the namespace:

namespace A {
class Bar;
}

class User {
A::Bar* pBar;
}

br,
Martin


tech写道:
tech wrote:

我有以下问题


在file1.h


名称空间A

{

类酒吧

{

void foo();


};


}


在file2.h
Hi, i have the following problem

In file1.h

namespace A
{
class Bar
{
void foo();

};

}
In file2.h



添加


名称空间A {

Add

namespace A {


>

级酒吧;
>
class Bar;



添加


}

Add

}


>

类用户

{


Bar * pBar;


};


在file2.cpp

#include" file2.h"

#include" file1.h"


User :: func()

{


pBar = new Bar;

pBar-> foo(); //链接器错误这里

}


如果我尝试在file2.h中转发声明这样的


class A :: Bar我得到一个编译器错误,说A不是一个类或

命名空间

和MSVC ++ 8.


如何解决这个问题。
>
class User
{

Bar* pBar;

};
In file2.cpp

#include "file2.h"
#include "file1.h"

User::func()
{

pBar = new Bar;
pBar->foo(); // linker error here
}
If i try to forward declare in file2.h like this

class A::Bar i get a compiler error saying that A is not a class or
namespace
with MSVC++8.

How to solve this issue.



你必须告诉编译器'A''是命名空间。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要''请问

You have to tell the compiler that ''A'' is a namespace.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


谢谢,现在我还有另外一个问题


在file1.h

命名空间A

{

class Bar

{

void foo();

};

}


file1.cpp


命名空间A

{

Bar :: Bar()

{

}

}

In file2.h

命名空间A {

类吧;

}


类用户

{

A :: Bar * pBar;


};

in file2.cpp


#include" file2.h"

#include" file1.h"

User :: func()

{


pBar = new A :: Bar;

pBar-> foo();


}

现在我有编译错误,说Bar没有默认构造函数
Hi, thanks now i have another problem though

In file1.h
namespace A
{
class Bar
{
void foo();
};
}

file1.cpp

namespace A
{
Bar::Bar()
{
}
}
In file2.h
namespace A {
class Bar;
}

class User
{
A::Bar* pBar;

};
In file2.cpp

#include "file2.h"
#include "file1.h"
User::func()
{

pBar = new A::Bar;
pBar->foo();

}
Now i have compiler error saying Bar has no default constructor


这篇关于命名空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆