[编译记录]关于编译器错误C2885...

来源:互联网 发布:我们相遇网络歌词 编辑:程序博客网 时间:2024/05/20 02:27
namespace fear {
namespace ai {
namespace rbs {
using RuleBasedSystemBase::Rule;
using RuleBasedSystemBase::Rule;
class RuleBasedSystemInterface{};
}
}
}

C2885编译错误....VC8中似乎一定要把using声明放在类内。
把using 写到类内就可以了...

class RuleBasedSystemInterface
{
public:
};
}
}
}

以下为MSDN上的说明...
Visual C++ 概念: 建置 C/C++ 程式
編譯器錯誤 C2885

錯誤訊息

'class::identifier': 在非類別範圍不是有效的 using 宣告

using 宣告的使用不正確。

範例

對 Visual C++ 2005 完成一致性處理後可能會產生這項錯誤:讓 using 宣告至巢狀型別已不再有效;您必須明確限定至巢狀型別的各個參考,將型別置於命名空間中,或是建立 typedef。如需詳細資訊,請參閱 Breaking Changes in the Visual C++ 2005 Compiler

下列範例會產生 C2885。

// C2885.cpp
namespace MyNamespace {
class X1 {};
}

struct MyStruct {
struct X1 {
int i;
};
};

int main () {
using MyStruct::X1; // C2885

// OK
using MyNamespace::X1;
X1 myX1;

MyStruct::X1 X12;

typedef MyStruct::X1 abc;
abc X13;
X13.i = 9;
}

如果您將 using 關鍵字和類別成員一起使用,則 C++ 會要求您在另一個類別 (衍生類別) 之中定義該成員。

下列範例會產生 C2885。

// C2885_b.cpp
// compile with: /c
class A {
public:
int i;
};

void z() {
using A::i; // C2885 not in a class
}

class B : public A {
public:
using A::i;
};
 

引用MSDN改变说明...


5. A using declaration of nested type is now illegal

Affected User Scenario:

Customers that have a using declaration with a nested type  will now get C2885. 

Description:

Before users where allowed to bring in a nested type's declaration to global scope by a using declaration.  This is not allowed in Standard C++. 

Customer Workaround:

Customer workaround is to fully qualify his nested type whenever he wants to use it.  A typedef can also be used to bypass using the scope resolution operator everywhere. 

Rationale:

The using declaration cannot be used with nested classes, the C++ Standard specifies that it can be used to bring a class into the scope that is contained in a namespace, not a class.

原创粉丝点击