A!die Software Studio Welcome to A!Die Software Studio

什么是 unqualified-id?

翻译: adie
日期: Jun,2011
原文作者: DevNull
原文地址: http://bytes.com/topic/c/answers/552463-what-unqualified-id
DevNull
 
#1:Oct 20 '06

大家好,
我希望有人能给我详细解释一下什么是 unqualified-id? 我在网上反复搜索也没弄明白.
我的编译器显示了如下错误...

ThreadLibMutex.h:37: error: expected unqualified-id before ')' token

我的第 37 行是这个构造函数的开始...

  1. Mutex(){  
  2. #ifdef WIN32  
  3.     // we use critical sections in Windows  
  4.     InitializeCriticalSection( &m_mutex );  
  5. #else  
  6.     pthread_mutex_init( &m_mutex, 0 );  
  7. #endif  
  8. }  

这个类本身被定义在这前面,内容是....

  1. class Mutex {  
  2. protected:  
  3.     // define the base mutex types  
  4. #ifdef WIN32  
  5.     CRITICAL_SECTION m_mutex;  
  6. #else  
  7.     pthread_mutex_t m_mutex;  
  8. #endif  
  9. public:  
  10.     inline void Lock() {  
  11. #ifdef WIN32  
  12.         EnterCriticalSection( &m_mutex );  
  13. #else  
  14.         pthread_mutex_lock( &m_mutex );  
  15. #endif  
  16.     }  
  17.   
  18.     inline void Unlock() {  
  19. #ifdef WIN32  
  20.         LeaveCriticalSection( &m_mutex );  
  21. #else  
  22.         pthread_mutex_unlock( &m_mutex );  
  23. #endif  
  24.     }  
  25. }; // end class Mutex  

我从未听说过 unqualified-id, 不知道哪里错了, 我感觉代码看起来没什么问题呀. 希望大家能给点建议, 谢谢大家!


Ron Natalie
 
#2: Oct 20 '06

DevNull 说到:

Hello,
I've searched and searched and cannot seem to figure it out so I was
hoping someone could explain to me exactly what an unqualified-id is?
>
My compiler is generating this error...
ThreadLibMutex.h:37: error: expected unqualified-id before ')'
token
>
My line 37 is the top of this constructor...
>
Mutex(){]
我觉得应该是微软通过 #define 把 Mutex 定义成了其他什么东西.

Alf P. Steinbach
 
#3: Oct 20 '06

* DevNull:

Hello,
I've searched and searched and cannot seem to figure it out so I was
hoping someone could explain to me exactly what an unqualified-id is?
>
My compiler is generating this error...
ThreadLibMutex.h:37: error: expected unqualified-id before ')'
token
>
My line 37 is the top of this constructor...
>
Mutex(){
#ifdef WIN32
// we use critical sections in Windows
InitializeCriticalSection( &m_mutex );
#else
pthread_mutex_init( &m_mutex, 0 );
#endif
}
>
正如 Ron Natalie 所说(注意, 微软定义的宏到处都是), 另外, 试试看用限定的标示符(qualified id) 怎么样:

Mutex::Mutex()

;-)

--

DevNull
 
#4: Oct 20 '06


<引用>

What Ron Natalie said (look out! Microsoft macros everywhere! or, as Dan
Quayle would have said, Microsoft macroes everywhere!), plus, try using
the qualified id
>
Mutex::Mutex()
>
;-)
</引用>

这样更糟了...
ThreadLibMutex.h:35: error: definition of implicitly-declared 'Mutex::Mutex()'
ThreadLibMutex.h:35: error: declaration of 'Mutex::Mutex()' throws different exceptions
ThreadLibMutex.h:9: error: than previous declaration 'Mutex::Mutex() throw ()'

第 9 行是 Mutex 类的位置. 另外, 这也不光是用在微软的平台下的, 我正在用 GCC v4.0.3 编译这段代码. 我只是想做一个简单的跨平台包装器 :(, 如果谁感兴趣, 我可以贴出全部代码, 一共只有 49 行.

Ron Natalie
 
#5:Oct 20 '06

DevNull 写到:

<引用>
>What Ron Natalie said (look out! Microsoft macros everywhere! or, as Dan
>Quayle would have said, Microsoft macroes everywhere!), plus, try using
>the qualified id
>>
> Mutex::Mutex()
>>
>;-)
</引用>\
试试在那几行前加 #undef Mutex 看看

未修饰的标示符(unqualified id) 是指里面没有 :: 界定的.

在类定义中没有什么需要修饰的.

Michael
 
#6: Oct 20 '06

Nope that made things worse...
ThreadLibMutex.h:35: error: definition of implicitly-declared
'Mutex::Mutex()'
ThreadLibMutex.h:35: error: declaration of 'Mutex::Mutex()' throws
different exceptions
ThreadLibMutex.h:9: error: than previous declaration 'Mutex::Mutex()
throw ()'
看看编译器的提示, 别老是抱怨微软.

在你的类定义中声明构造函数. . .

DevNull
 
#7: Oct 20 '06

太好了!
<引用>

Declare the constructor in your class definition. . .
</引用>
非常感谢!
这样可以运行了.

Rolf Magnus
 
#8: Oct 20 '06

DevNull 写到:

If anyone is interested I can post the complete source. It's only 49
lines of code in total.
这个主意不错.


Alf P. Steinbach
 
#9: Oct 20 '06

* DevNull:

<snip>
>What Ron Natalie said (look out! Microsoft macros everywhere! or, as Dan
>Quayle would have said, Microsoft macroes everywhere!), plus, try using
>the qualified id
>>
> Mutex::Mutex()
>>
>;-)
</snip>
>
Nope that made things worse...
ThreadLibMutex.h:35: error: definition of implicitly-declared
'Mutex::Mutex()'
你还需要在类定义中声明构造函数.



▲评论

› 网友 匿名 () 于 2013-12-23 09:52:50 发表评论说:

我也遇到了这个问题,但我还是没看懂该怎么弄

› 网友 匿名 () 于 2021-04-10 21:01:15 发表评论说:

what does un qualified means??

X 正在回复:
姓 名: 留下更多信息
性 别:
邮 件:
主 页:
Q Q:
来 自:
职 业:
评 论:
验 证:


Valid HTML 4.01 Strict Valid CSS!
Copyleft.A!die Software Studio.ADSS
Power by webmaster@adintr.com