Skip to content

Instantly share code, notes, and snippets.

@Getaji
Created November 16, 2013 11:20
Show Gist options
  • Save Getaji/7499065 to your computer and use it in GitHub Desktop.
Save Getaji/7499065 to your computer and use it in GitHub Desktop.
テンプレートについて忘れないようにメモ。
import std.stdio;
template Temp()
{
private:
string name_;
public:
string name() { return name_; }
this(string name) { name_ = name; }
}
class Person
{
mixin Temp;
public:
@property
{
string name() const { return name_; }
void say() const { writeln("Hello, I am ", name_, "!"); }
}
}
class Enemy
{
mixin Temp;
public:
void shout() const { writeln("I am ", name_, "! I'm kill you!!"); }
}
int main(string[] argv)
{
auto getaji = new Person("Getaji");
auto slime = new Enemy("Slime");
writeln("Name:", getaji.name);
getaji.say;
slime.shout();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment