jeudi 30 juin 2016

how can I copy vector in c++ by refference?

I want to have class scope allice to the vector from an argument.

For exapmale:

class Solution {
public:
     vector<int> a;
     int maxCoins(vector<int>& _a) {
          // here I want to do smth like a = _a; which works for O(1)
     }
};

Unfortunatelly, I can't just declare vector<int> &a; , because of the error: declaration of reference variable 'a' requires an initializer

Could you please, explain how to do it in C++11/14?

Aucun commentaire:

Enregistrer un commentaire