c++ - Why is an "empty attribute block" not allowed? -


this may dumbest question asked today regardless i'm going press on:

the following derived class overloaded operator +=, base class of overloads operator [] gives following compiler error :

empty attribute block not allowed

i write v[0] , v[1] in operator += of course, curious whether compile , if not, why not.

what attribute block? why doesn't compiler resolve [0] [] operator, returning reference base class? question of syntax or deeper?

#include <array>  template<class t, int c> struct vec {     typedef t value_type;     typedef unsigned index_type;     typedef unsigned size_type;      std::array<t, c> v;      template<typename ...args>     explicit vec(args&&... args) : v({{args...}}) {}     vec(std::array<t, c> const & o) : v(o) {}      value_type & operator [] (index_type i)     {                    return v[i];     }      value_type const & operator [] (index_type i) const     {         return v[i];     } };   template<class t> struct vec2 : vec<t, 2> {     template<typename ...args>     explicit vec2(args... args) : vec<t, 2>(args...) {}     vec2(vec2<t> const & p) : vec<t, 2>(p.v) {}           vec2<t> & operator += (vec2<t> const & q)     {         [0] += q[0];         [1] += q[1];          return *this;     } };  int main(void) {     vec2<int> a(10, 20);     vec2<int> b(30, 40);      += b;      return 0; } 

change operator+= call operator[], statement [0] not valid c++.

    vec2<t> & operator += (vec2<t> const & q) {     operator[](0) += q[0];     operator[](1) += q[1];      return *this; } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -