Thread overview
Why is this code returning the wrong type?
May 23, 2013
Gary Willoughby
May 23, 2013
David
May 23, 2013
John Colvin
May 23, 2013
Gary Willoughby
May 23, 2013
Gary Willoughby
May 23, 2013
dennis luehring
May 23, 2013
Gary Willoughby
May 23, 2013
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 _file

Gah! of course. Thanks. I think i better get some sleep...