2017-04-25 5 views
1

私の問題は、アプリケーションを実行するためのメインコンポーネントであるループが実行されていないため、私の基本ケースが実行されないということです。私は埋め込みforループを作ることを考えていましたが、forループをmaxベクトル位置から最小ベクトル位置に振動させる方法は考えられませんでした。パラメータby valueを渡すとは異なるhttp://coliru.stacked-crooked.com/a/c6fdc017118e98f2ループを介して再帰的な操作

void Obj::objhelper() 
    { 

     recurisivehelper(); 


     if ((v1[0].getx() == 0 && v2[0].getx() > 0) || 
      (v1[0].getx() > 0 && v2[0].getx() == 0)) 
     { 
      if (v1[0].getx() == 0 && v2[0].getx() > 0) 
      { 
       print(3); 
       return; 
      }else 
      { 
       print(4); 
       return; 
      } 
     } 

     else if(v1[0].getx() > 0 && v2[0].getx() > 0) 
     { 
      objhelper(); 
     } 

     return; 
    } 

//This method is not touched 
//This is a recursive helper method of the helper method of the main method 
    void Obj::recursivehelper() 
    { 

     for (int i = 0; i < 2; i++) { 

      if (v3[i].gety() == "str1" || 
       v3[i].gety() == "str2" || 
       v3[i].gety() == "str3") 
      { 
       int temp = 0; 

       Obj1 obj(v1,:v2); 
       obj.display(); 

       v3[i].doa(v3[i + 1]); 

       obj.display(); 
       v2[0]--; 
      }else if (v3[i].gety() == "str4" || 
         v3[i].gety() == "str5" || 
         v3[i].gety() == "str6" ) 
      { 

       Obj1 obj(v1,sv2); 
       obj.display(); 

       v3[i].doa(v3[i + 1]); 


       obj.display(); 
       v1[0]--; 
      } 
     } 

     return; 
    } 
+1

[MCVE](https://stackoverflow.com/help/mcve)を投稿した場合、実行可能なメインでhttp://ideone.com/またはhttp://coliru.stacked-crooked.com/でこの問題は解決するのが非常に魅力的です。 – javaLover

+0

ここにはC++でのMCVE版がありますhttp://coliru.stacked-crooked.com/a/a268bd6b5618a768 – KRYMauL

+0

ニース、それははるかに良いです。しかし、それはコンパイル可能ではないので、この質問はコンパイラエラーを尋ねる以外はまだMCVEではありません。 ...私は誰かがこの質問を見つめていると思います。あなたがMCVEを提供するとすぐにすぐに答えが出ます。 – javaLover

答えて

0

:MCVEバージョン

オブジェクトCがAのスーパークラスであるため、及びB.また、表示する前に注意すべき小さなものはV3は、オブジェクトAとBの両方を含んでいます passing by reference。ここ

が問題一部である: -

void recursivehelper(std::vector<int>v1, std::vector<int>v2, std::vector<std::string>v3) { 
    .... 
     v1[0]--; //<-- modify internal copy 
     v2[0]--; 
    ... 
    return; 
} 

v1[0]--;v2[0]--;v1v2コピーを変更し、実際の発信者(recursivefunc())の観点から効果v1又はv2何もしません。

期待通りに動作させる簡単な方法の1つは、参照渡しです。

変更

void recursivefunc(std::vector<int>, std::vector<int>, std::vector<std::string>); 
void recursivehelper(std::vector<int>, std::vector<int>, std::vector<std::string>); 

から

void recursivefunc(std::vector<int>&, std::vector<int>&, std::vector<std::string>&); 
void recursivehelper(std::vector<int>&, std::vector<int>&, std::vector<std::string>&); 

に宣言と実装の両方の署名がここdemoあります。

関連する問題