Error: function declaration without return type.
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 7 15:12:06 PST 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
More information about the Digitalmars-d-learn
mailing list