www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Read property using std.stream.Stream.read

reply nrgyzer <nrgyzer gmail.com> writes:
Hi guys,

I'm trying to read a property of a class like:

class MyClass {

   private ubyte pToRead;

    property ubyte toRead() { return pToRead; }

}

...
File f = new File(...);
MyClass c = new MyClass();
f.read(c.toRead);
...

but when I compile my code, I always get:

executable.d(389): Error: function std.stream.Stream.read (ubyte[]
buffer) is not callable using argument types (ubyte)
executable.d(389): Error: cannot implicitly convert expression
(c.toRead()) of type ubyte to wchar[]
Aug 13 2011
parent nrgyzer <nrgyzer gmail.com> writes:
== Auszug aus nrgyzer (nrgyzer gmail.com)'s Artikel
 Hi guys,
 I'm trying to read a property of a class like:
 class MyClass {
    private ubyte pToRead;
     property ubyte toRead() { return pToRead; }
 }
 ...
 File f = new File(...);
 MyClass c = new MyClass();
 f.read(c.toRead);
 ...
 but when I compile my code, I always get:
 executable.d(389): Error: function std.stream.Stream.read (ubyte[]
 buffer) is not callable using argument types (ubyte)
 executable.d(389): Error: cannot implicitly convert expression
 (c.toRead()) of type ubyte to wchar[]

Answering my own question ;D - I solved it by adding "ref" to my property like: property ref ubyte toRead() { return pToRead; }
Aug 13 2011