digitalmars.D.learn - Why is this code returning the wrong type?
- Gary Willoughby (24/24) May 23 2013 Why won't the following code compile? Here's the error:
- David (3/31) May 23 2013 Because that's not the same: File != FILE
- John Colvin (25/49) May 23 2013 /**
- Gary Willoughby (1/4) May 23 2013 Ah yes, thanks.
- Gary Willoughby (15/15) May 23 2013 Hmmm... Following your example i'm still having problems
- dennis luehring (8/23) May 23 2013 you former
- Gary Willoughby (1/8) May 23 2013 Gah! of course. Thanks. I think i better get some sleep...
Why won't the following code compile? Here's the error: filewatcher.d(21): Error: cannot implicitly convert expression (new File(file, "r")) of type File* to shared(_iobuf)* /** * Imports. */ import std.stdio; /** * A class to watch for changes in a file. */ class Example { /** * Member variables. */ private FILE* _file; /** * Constructor. */ public this(string file) { this._file = new File(file, "r"); } }
May 23 2013
Am 23.05.2013 18:27, schrieb Gary Willoughby:Why won't the following code compile? Here's the error: filewatcher.d(21): Error: cannot implicitly convert expression (new File(file, "r")) of type File* to shared(_iobuf)* /** * Imports. */ import std.stdio; /** * A class to watch for changes in a file. */ class Example { /** * Member variables. */ private FILE* _file; /** * Constructor. */ public this(string file) { this._file = new File(file, "r"); } }Because that's not the same: File != FILE you probably want the .handle
May 23 2013
On Thursday, 23 May 2013 at 16:27:19 UTC, Gary Willoughby wrote:Why won't the following code compile? Here's the error: filewatcher.d(21): Error: cannot implicitly convert expression (new File(file, "r")) of type File* to shared(_iobuf)* /** * Imports. */ import std.stdio; /** * A class to watch for changes in a file. */ class Example { /** * Member variables. */ private FILE* _file; /** * Constructor. */ public this(string file) { this._file = new File(file, "r"); } }/** * Imports. */ import std.stdio; /** * A class to watch for changes in a file. */ class Example { /** * Member variables. */ private File _file; /** * Constructor. */ public this(string file) { _file = File(file, "r"); } } File is a wrapper around a FILE*, it's not the same as a FILE* No need for new, File is a struct, new is (normally) for classes. No need for "this.", although there's no harm in it.
May 23 2013
File is a wrapper around a FILE*, it's not the same as a FILE* No need for new, File is a struct, new is (normally) for classes. No need for "this.", although there's no harm in it.Ah yes, thanks.
May 23 2013
Hmmm... Following your example i'm still having problems compiling this simple snippet: import std.stdio; class Example { private FILE _file; public this(string file) { this._file = File(file, "r"); } } Error: test.d(9): Error: cannot implicitly convert expression ((File __ctmp1220 = 0; , __ctmp1220).this(file, "r")) of type File to shared(_iobuf)
May 23 2013
Am 23.05.2013 21:45, schrieb Gary Willoughby:Hmmm... Following your example i'm still having problems compiling this simple snippet: import std.stdio; class Example { private FILE _file; public this(string file) { this._file = File(file, "r"); } } Error: test.d(9): Error: cannot implicitly convert expression ((File __ctmp1220 = 0; , __ctmp1220).this(file, "r")) of type File to shared(_iobuf)you former private FILE* _file wasn't an File and your current private FILE _file is still not File because FILE and File is something differnt (case sensitive) why not write private File _file
May 23 2013
you former private FILE* _file wasn't an File and your current private FILE _file is still not File because FILE and File is something differnt (case sensitive) why not write private File _fileGah! of course. Thanks. I think i better get some sleep...
May 23 2013