www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error: function declaration without return type.

reply "Suliman" <evermind live.ru> writes:
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?
Jan 06 2015
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Suliman:

 	void foo()
 	{
 	writeln("test");
 	writeln(mystring);
 	}
 	foo();   <<<<<
 }
I guess you have to remove that line. Bye, bearophile
Jan 06 2015
parent reply "Suliman" <evermind live.ru> writes:
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?
Jan 06 2015
next sibling parent =?UTF-8?B?TWFydGluIERyYcWhYXI=?= via Digitalmars-d-learn writes:
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
=20 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
Jan 06 2015
prev sibling next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
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
=20 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.
Jan 06 2015
parent reply "Suliman" <evermind live.ru> writes:
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
}
Jan 07 2015
parent "Tobias Pankrath" <tobias pankrath.net> writes:
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.
Jan 07 2015
prev sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Jan 07 2015