1

Am I declaring the iterators of the derived class r_iter and c_iter properly ? Inside the derived class, r_iter is a iterator of a 2D vector and c_iter is iterator into the 2 D vector.

I'm getting the following error and I'd really appreciate if somebody tells me where I'm wrong

add_round_key.cpp:26:34: error: expected class-name before ‘{’ token
add_round_key.cpp:27:2: error: ‘dVector’ is not a template
add_round_key.cpp:27:11: error: ‘dVector’ is not a template
add_round_key.cpp:27:28: error: invalid use of ‘::’
add_round_key.cpp: In member function ‘void dVector::RotWord()’:
add_round_key.cpp:37:2: error: ‘r_iter’ was not declared in this scope
add_round_key.cpp:37:17: error: ‘class dVector’ has no member named ‘begin’
add_round_key.cpp:38:2: error: ‘c_iter’ was not declared in this scope





line# 26    class dVector:public std::vector {
line# 27             dVector <dVector <int> >::iterator r_iter;
                     dVector <int>::iterator c_iter;

                      public:
                      void RotWord();
                        void SubWord();
              };

            void dVector::RotWord() {
                  int temp ;
line# 37          r_iter = this->begin(); 
     #38          c_iter = (*r_iter).end();
                 *(c_iter) = *(c_iter+4);
               *(c_iter+4) = *(c_iter+8);
            }


          void dVector::SubWord(){
              //function definition
        }

    int main (int argc, char *argv[]) 
    {

        /*wordArray is a 4x4 word array stored in column-order form*/
        dVector <dVector <int> > wordArray(4,dVector<int>(40,0));
        dVector <dVector <int> >::iterator ckIter,i ,j, row_iter;
        dVector <int>::iterator ii,jj, col_iter;
        wordArray.RotWord();
        wordArray.Subword();
    }
Sharat Chandra
  • 4,434
  • 7
  • 49
  • 66

2 Answers2

2

Line 26: std::vector is a template you need to tell it what to specialize on to make it a class you can inherit.

Line 26 Bonus: Avoid inheriting from std containers

Line 27: Is dVector a template? If it's not you can't use it as if it is!

Lines 37-38: Errors in lines 27 and 28 cause r_iter and c_iter not to be declared, thus the errors you're getting on these lines.

That said, this might help you accomplish what you're trying to do:

template<class T>
class dVector : public std::vector<T> {
   typename dVector <dVector <T> >::iterator r_iter;
   typename dVector <T>::iterator c_iter;

But the advice still remains, don't inherit from std containers.

Community
  • 1
  • 1
Pablo
  • 8,644
  • 2
  • 39
  • 29
0

I think you're forgetting to assign a template type to std::vector before inheriting from it.

class dVector:public std::vector {        // Not valid

class dVector:public std::vector<int> {   // Valid