[SOLVED] Must use 'this' to access member!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lifo
    New Member
    • Oct 2008
    • 4

    #1

    [SOLVED] Must use 'this' to access member!

    Hi,
    the following piece of code can correctly compile (g++ 4.1.2) only if 'this' is specified. Otherwise, it gives the error: 'i' was not declared in this scope (?). Inheriting from, say, X<int> doesn't lead to this problem! I find this rather odd... any hints? Compiler bug?

    template<class T> struct X {
    int i; // dummy type
    };
    template<class T> struct Y : public X<T> {
    Y() { this->i = 100; }
    };

    int main() {
    Y<double> y; // dummy type
    }
  • Lifo
    New Member
    • Oct 2008
    • 4

    #2
    Originally posted by Lifo
    Hi,
    the following piece of code can correctly compile (g++ 4.1.2) only if 'this' is specified. Otherwise, it gives the error: 'i' was not declared in this scope (?). Inheriting from, say, X<int> doesn't lead to this problem! I find this rather odd... any hints? Compiler bug?
    Compiler bug: g++ 3.3.6 works fine, while 3.4.6 doesn't. Still didn't try last stable g++ available (4.3.2).

    Comment

    • Lifo
      New Member
      • Oct 2008
      • 4

      #3
      Originally posted by Lifo
      Compiler bug: g++ 3.3.6 works fine, while 3.4.6 doesn't. Still didn't try last stable g++ available (4.3.2).
      4.3.2 buggy, too! I'll notify it.

      Comment

      • Lifo
        New Member
        • Oct 2008
        • 4

        #4
        for those who may be interested: NOT bug!

        http://gcc.gnu.org/bugzilla/show_bug.cgi?id =37910

        Comment

        Working...