constant references : reference « Data Type « C++






constant references

  
#include <iostream>
#include <string>
#include <vector>

using namespace std;

//a constant reference to a vector of strings
void display(const vector<string>& v);

int main()
{
    vector<string> v;
    v.push_back("A");
    v.push_back("B");
    v.push_back("C");  
    
    display(v);

    return 0;
}

void display(const vector<string>& vec)
{
    for (vector<string>::const_iterator iter = vec.begin(); 
         iter != vec.end(); ++iter)
         cout << *iter << endl;
}
  
    
  








Related examples in the same category

1.returning a reference to a string
2.using references for int
3.Reassigning a reference
4.Taking the Address of a Reference
5.swap() Rewritten with References
6.Passing by Reference Using Pointers
7.Passing Objects by Reference
8.Passing References to Objects
9.Returning multiple values from a function using references
10.Creating and Using References for integer
11.Data Slicing With Passing by Value
12.References for int type variable