How to access member functions from pointer to a vector in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

template<typename T>
void printVector(std::vector<T> *p) {
    for (auto i = 0; i < p->size(); i++) {
        std::cout << p->at(i) << " ";
    }
}

int main() {
    std::vector<std::string> v = {"python", "c", "c++", "java"};

    printVector(&v);

    return 0;
}




/*
run:

python c c++ java 

*/

 



answered May 14, 2021 by avibootz

Related questions

...