By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

What is causing this error: expected constructor, destructor, or type conversi

P: 2
I can not see what is causing this error....
iterator has been defined properly, but the error seems to point to the interator type.

Errors I get with g++ svector.c++ -o svector 2> ./err_txt
gcc version 4.3.2

svector.c++:38: error: expected constructor, destructor, or type conversion before ‘SVector’
svector.c++:53: error: expected constructor, destructor, or type conversion before ‘SVector’
svector.c++:63: error: expected constructor, destructor, or type conversion before ‘SVector’
svector.c++:68: error: expected constructor, destructor, or type conversion before ‘SVector’

Expand|Select|Wrap|Line Numbers
  1. #include <iostream> 
  2. #include <vector>
  3.  
  4. #define comp(a,b) \
  5.        ({ typeof (a) _a = (a); \
  6.            typeof (b) _b = (b); \
  7.          _a > _b ? 1 : (_a < _b ? -1 : 0); })
  8.  
  9. #define TINEY 3
  10.  
  11. using namespace std;
  12.  
  13. template <class T>
  14. class SVector 
  15. public:
  16.    typedef typename vector<T>::iterator iterator;
  17.    typedef typename vector<T>::const_iterator const_iterator;
  18.    SVector() {};
  19.    ~SVector() {};
  20.    iterator put(T);
  21.    T get(iterator);
  22.    T operator[](unsigned int);
  23.    unsigned int size() { v.size(); };
  24.    const_iterator begin()const{return v.begin();};
  25.    const_iterator end()const{return v.end();};
  26.    iterator begin(){return v.begin();};
  27.    iterator end(){return v.end();};
  28. private:
  29.    vector<T> v;
  30.    iterator bsearch(unsigned int, unsigned int, T);
  31.    unsigned int isearch(unsigned int, unsigned int, T);
  32.    iterator push_before(iterator, T);
  33.    iterator push_after(iterator, T); 
  34. };
  35.  
  36.    template <class T>
  37.    iterator SVector<T>::put(T)  //line 38
  38.    {
  39.    }
  40.  
  41.    template <class T>
  42.    T SVector<T>::get(iterator)
  43.    {
  44.    }
  45.  
  46.    template <class T>
  47.    T SVector<T>::operator[](unsigned int)
  48.    {
  49.    }
  50.  
  51.    template <class T>
  52.    iterator SVector<T>::bsearch(unsigned int, unsigned int, T)   // line 53
  53.    {
  54.    }
  55.  
  56.    template <class T>
  57.    unsigned int SVector<T>::isearch(unsigned int, unsigned int, T)
  58.    {  
  59.    }
  60.  
  61.    template <class T>
  62.    iterator SVector<T>::push_before(iterator, T) // line 63
  63.    {
  64.    }
  65.  
  66.    template <class T>
  67.    iterator SVector<T>::push_after(iterator, T) //line 68
  68.    {
  69.    }
  70.  
Mar 11 '10 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
You have used the type iterator as the return value. Your code does not define a type iterator at global scope but it does define a type SVector<T>::iterator, is that what you meant to use?
Mar 11 '10 #2

P: 1
I am unsure but you could try declaring your iterator functions as: 'vector<T>::iterator SVector<T>::functionname(param)'. I just found myself in a similar situation. The typedef is not global so you probably would have to make the functions of type iterator into functions of type SVector<T>.
Nov 30 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.