www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 830] New: Access to static member variable causes Access Violation

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=830

           Summary: Access to static member variable causes Access Violation
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: ralfs72 gmx.net


void main(char[][] args)
{
        class A
        {
                static int v = 1;

                int getv()
                {
                        return v;
                }
        }

        A a;
        assert (a.getv() == 1);
}

==> Access Violation


-- 
Jan 11 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=830






this ain't a bug. coz getv ain't static


-- 
Jan 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=830







 this ain't a bug. coz getv ain't static
 
And? What's the problem with it? Is it not possible to access static vars in a member function? Of course the opposite way can not work: Access non static member vars from a static member function. Well the equivalent C++ programm works: class A { public: static int v; int getv() { return v; } }; int A::v = 1; int _tmain(int argc, _TCHAR* argv[]) { A a; printf("%d\n", a.getv()); } --
Jan 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=830






your instance of A is null

This should work:

void main(char[][] args)
{
        class A
        {
                static int v = 1;

                int getv()
                {
                        return v;
                }
        }

        A a = new A;
        assert (a.getv() == 1);
}


-- 
Jan 11 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=830


ralfs72 gmx.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID






 your instance of A is null
 
 This should work:
 
 void main(char[][] args)
 {
         class A
         {
                 static int v = 1;
 
                 int getv()
                 {
                         return v;
                 }
         }
 
         A a = new A;
         assert (a.getv() == 1);
 }
 
OHH! Sorry! I have to get used to that classes are allways references! Sorry again! - I put it to INVALID --
Jan 11 2007