1

addBranch 関数を呼び出すときに配列を 1 つ拡張し、その拡張された空の領域に新しい Branch オブジェクトを追加して、コードのメモリ リークを防止しようとしています。私は正しいと思っていましたが、この機能にこだわっています。

バイナリ '=' : タイプ 'Branch *' の右側のオペランドを取る演算子が見つかりません (または、受け入れ可能な変換がありません)」というエラーが表示されます。関数の削除後に削除されない新しい Branch オブジェクトに最後の要素を割り当てるには、ここで助けが必要です。私はC++の初心者なので、大きな間違いがあるかもしれません。ベクターなどの使用は許可されていません。

  // ------- Adds a branch to system -------- //
    void BankingSystem::addBranch(const int id, const string name){
        if(isBranchExisting(id)){
            cout << "\n\tBranch " << id << " already exists. Please try it with another id number.";
        }
        else if(!isBranchExisting(id)){
            Branch* tempArray = new Branch[cntAccounts];
            for(int i = 0; i<cntAccounts; i++){
                tempArray[i] = allBranches[i];
            }

            delete[] allBranches;

            allBranches = new Branch[cntAccounts+1];
            for(int i = 0; i<cntAccounts; i++){
                allBranches[i] = tempArray[i];
            }
            allBranches[cntAccounts] = new Branch(id, name);  // error at this line

        }
    }
4

1 に答える 1