c++11 - call functions from vector of class in c++ -


i writing program insertion sort.i creating class read print , sort vector of integers.i have created vector of class , want call functions read,sort , print vector of class created.how ?

thanks,

#include <iostream> #include <vector>  using namespace std;  class sorting { private:     vector<int>arr;  public:     void read();     void sortt();     void print(); };  void sorting :: read() {     int n;      cin>>n;      for(int i=0; i<n; i++)     {         int t;         cin>>t;         arr.push_back(t);     }  }   void sorting :: sortt() {     int j,temp;      for(unsigned int i=0; i<arr.size(); i++)     {         temp=arr[i];         j=i;          while(temp<arr[j-1] && j>0)         {             arr[j]=arr[j-1];             j=j-1;          }         arr[j]=temp;     } }  void sorting :: print() {     for(unsigned int k=0; k<arr.size(); k++)     {         cout<<arr[k]<<"\t";      }     cout<<endl;     arr.clear(); }   int main() {     vector<sorting>s;      s.read(); // giving error     s.sortt(); // giving error      return 0; } 

it should sorting s; , not vector<sorting>. defined methods read() amd sortt() defined in class sorting.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo