7

私が以下を持っている場合:

class T
{
   public: 
      T(){}
};

void T()
{
}

int main()
{
  T(); // this calls the function, how can I call the constructor T()?
}

名前を変更できる可能性があるため、問題はありませんが、コンストラクターを強制的に呼び出す方法に興味があり、関数呼び出しがコンストラクターよりも優先される理由を自問しています。さらに、名前の重複に関する警告メッセージが表示されないのはなぜですか。

4

2 に答える 2

3

jaunchopanzaが言ったことに加えて、あなたは電話を修飾することができます:

T::T();

このバージョンでは、一時的なものを作成できます。

class T
{
   public: 
      T(){}
};

void foo(T) {}

void T()
{
}

int main(){
   foo(T::T());
}
于 2012-05-07T14:46:52.423 に答える
0

基本的に、名前の衝突はありません、基本的に、異なる名前空間にあります

T() ==> namespace::T() It;s a function call not an object instantiation. 
T a() ==> namespace ::T::T() It;s is instantiation of T class calling the constructor.
T a() ; a() ==>namespace ::T::T()::() It;s call the functor of the T Class (need to define the operator())    
于 2012-05-08T12:30:36.937 に答える