Thread overview
Error: function declaration without return type.
Jan 06, 2015
Suliman
Jan 06, 2015
bearophile
Jan 06, 2015
Suliman
Jan 06, 2015
Martin Drašar
Jan 07, 2015
ketmar
Jan 07, 2015
Suliman
Jan 07, 2015
Tobias Pankrath
Jan 07, 2015
Ali Çehreli
January 06, 2015
class Test
{
	string mystring;

	this(string mystring)
	{
		this.mystring = mystring;
	}
	
	void foo()
	{
	writeln("test");
	writeln(mystring);
	}
	foo();
}

source\app.d(303): Error: function declaration without return type. (Note that c
onstructors are always named 'this')
source\app.d(303): Error: no identifier for declarator foo()
FAIL .dub\build\application-debug-windows-x86-dmd_2066-EF7A441AE01F652132F0A1ED8
B06EB48\ seismodownloader executable
Error executing command run: dmd failed with exit code 1.

What I am doing wrong?
January 06, 2015
Suliman:

> 	void foo()
> 	{
> 	writeln("test");
> 	writeln(mystring);
> 	}
> 	foo();   <<<<<
> }

I guess you have to remove that line.

Bye,
bearophile
January 06, 2015
On Tuesday, 6 January 2015 at 21:19:38 UTC, bearophile wrote:
> Suliman:
>
>> 	void foo()
>> 	{
>> 	writeln("test");
>> 	writeln(mystring);
>> 	}
>> 	foo();   <<<<<
>> }
>
> I guess you have to remove that line.
>
> Bye,
> bearophile

Why? I can't call function in instance of class?
January 06, 2015
Dne 6.1.2015 v 22:25 Suliman via Digitalmars-d-learn napsal(a):
> On Tuesday, 6 January 2015 at 21:19:38 UTC, bearophile wrote:
>> Suliman:
>>
>>>     void foo()
>>>     {
>>>     writeln("test");
>>>     writeln(mystring);
>>>     }
>>>     foo();   <<<<<
>>> }
>>
>> I guess you have to remove that line.
>>
>> Bye,
>> bearophile
> 
> Why? I can't call function in instance of class?

What would that even mean? When would the function ran? If you want to call that function during instantiation, put it into constructor. If you want to call it sometime later, than you have to call it from somewhere else. But having a function call inside a class does not compute...

Martin



January 07, 2015
On Tue, 06 Jan 2015 21:25:49 +0000
Suliman via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> On Tuesday, 6 January 2015 at 21:19:38 UTC, bearophile wrote:
> > Suliman:
> >
> >> 	void foo()
> >> 	{
> >> 	writeln("test");
> >> 	writeln(mystring);
> >> 	}
> >> 	foo();   <<<<<
> >> }
> >
> > I guess you have to remove that line.
> >
> > Bye,
> > bearophile
> 
> Why? I can't call function in instance of class?
'cause dlang specs (which you read with a great care, aren't you?)
doesn't allow it.


January 07, 2015
thanks!

Am I right understand that in next code scope(exit) stmt.close(); occur after this execution? And it will close connection so stmt in function become unavailable.

	this(parseConfig parseconfig)
	{
	 [....]

		auto conn = ds.getConnection();
		scope(exit) conn.close();

		stmt = conn.createStatement();

		scope(exit) stmt.close(); //HERE

	}
void InsertData()
{
auto rs = stmt.executeUpdate(sqlinsert); // stmt now unreachable
}
January 07, 2015
On Wednesday, 7 January 2015 at 08:58:35 UTC, Suliman wrote:
> thanks!
>
> Am I right understand that in next code scope(exit) stmt.close(); occur after this execution? And it will close connection so stmt in function become unavailable.
>
> 	this(parseConfig parseconfig)
> 	{
> 	 [....]
>
> 		auto conn = ds.getConnection();
> 		scope(exit) conn.close();
>
> 		stmt = conn.createStatement();
>
> 		scope(exit) stmt.close(); //HERE
>
> 	} void InsertData()
> {
> auto rs = stmt.executeUpdate(sqlinsert); // stmt now unreachable
> }

scope(exit) executes at the exit of the inner most scope. Scopes end at '}'. Which is the very next line in this case.
January 07, 2015
On 01/06/2015 01:25 PM, Suliman wrote:> On Tuesday, 6 January 2015 at 21:19:38 UTC, bearophile wrote:
>> Suliman:
>>
>>>     void foo()
>>>     {
>>>     writeln("test");
>>>     writeln(mystring);
>>>     }
>>>     foo();   <<<<<
>>> }
>>
>> I guess you have to remove that line.
>>
>> Bye,
>> bearophile
>
> Why? I can't call function in instance of class?

Instances of classes are objects that are created by 'new'. So, yes, you can call member functions on instances of classes. There are two instances of Test in the following main():

import std.stdio;

class Test
{
    string mystring;

    this(string mystring)
    {
        this.mystring = mystring;
    }

    void foo()
    {
        writeln("test");
        writeln(mystring);
    }
}

void main()
{
    auto a = new Test("hello");
    auto b = new Test("hi");

    a.foo();
    b.foo();
}

Ali