qt_begin_namespace

1)

Qt Code:
Switch view
   
   
  1. QT_FORWARD_DECLARE_CLASS (
    QTableView

    )



QT_FORWARD_DECLARE_CLASS(QTableView)
To copy to clipboard, switch view to plain text mode 

Expands to:

Qt Code:
Switch view
   
   
  1. namespace
    Foo {
    class QTableView

    ; }

  2. using
    ::
    Foo
    ::
    QTableView

    ;



namespace Foo { class QTableView; }
using ::Foo::QTableView;
To copy to clipboard, switch view to plain text mode 


2)

Qt Code:
Switch view
   
   
  1. QT_BEGIN_NAMESPACE

  2. class QTableView

    ;

  3. QT_END_NAMESPACE



QT_BEGIN_NAMESPACE


class QTableView;
QT_END_NAMESPACE
To copy to clipboard, switch view to plain text mode 

Expands to:

Qt Code:
Switch view
   
   
  1. namespace
    Foo {

  2. class QTableView

    ;

  3. }



namespace Foo {
class QTableView;
}
To copy to clipboard, switch view to plain text mode 


3)

Qt Code:
Switch view
   
   
  1. class QTableView

    ;



class QTableView;
To copy to clipboard, switch view to plain text mode 

Will cause a conflict because QTableView is forward declared outside the appropriate namespace, whereas including <QTableView> in the .cpp file brings in another QTableView declared inside the namespace and <QtGlobal> says

Qt Code:
Switch view
   
   
  1. using
    namespace
    ::
    Foo
    ;


in order to make client code compile regardless of the Qt namespace usage. So QTableView becomes ambiguous and the

compiler doesn't know which one to use, QTableView or Foo::QTableView.







Summary: Plain "class QTableView;" works as long as Qt is not compiled in a namespace. Using the macros will

make your code more compatible. As far as I remember, for example the Eclipse integration requires Qt to

be compiled in a certain namespace.







http://www.qtcentre.org/threads/15946-What-s-effect-of-QT_BEGIN_NAMESPACE-Thanks


















using namespace ::Foo;
To copy to clipboard, switch view to plain text mode
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值