我临摹的一个 hello world。
大家看了以后不要说我无聊,临摹的是:
http://packages.debian.org/unstable/devel/hello
getopt.d
/**
* Copyright (c) 2004
* Juanjo Alvarez Martinez <juanjux@yahoo.es>
* Copyright (c) 2007 only Version:0.5
* jinheking <jinheking@gmail.com>
*
* Permission to use, copy, modify, dis ...
CaffeineBeverage.d
module CaffeineBeverage;
import std.stdio;
/**
*这个程序程序是为了测试templete模式使用
*
*/
public abstract class CaffineBeverage{
void prepareRecipe(){
boilWater(); ///烧水
brew(); ///浸制
pourInCup(); ///倒水
addCondiments(); ///加调味品
}
void boilWater(){
writefln("Bo ...
现在学习《Head First Design Pattern》,现在正看到第六章 the Command Pattern
我把书中的简单命令模式用D重写了一下,目的是大家共通学习!
import std.stdio;
/**
* 本程序是学习《Head First Design Pattern》做得程序,思想属于Head First
* 网址<a href="http://www.headfirstlabs.com/">http://www.headfirstlabs.com/</a>
* Authors: Caoqi
* version: 0.001
* Dat ...
函数原形已经给出:int p(int i, int N);
功能:调用该函数,打印如下格式的输出,例p(1, 7);
1
2
3
4
5
6
7
6
5
4
3
2
1
即每行一个数字。(注意:N只打印一次)
要求:
函数中唯一能够调用的函数就是printf。
只使用一条语句,如果你真的不能用一条语句,每增加一条语句扣1分。
不准使用如下的关键字:typedef, enum, do, while, for, switch, case, break, continue, goto,
until, if, ..具体很多我也忘了,反正能用的不多。
不能使用逗号表达式和?:表达式。
标准:(总分1 ...
//module jdk2d.lang;
import std.stdio;
import std.string;
/**
* The <code>String</code> class represents character strings. All
* string literals in D programs, such as <code>String str=new String("abc");</code>,
* <br /><code>str="Hello world";</code>
* are implement ...
/**
* <code>s1>s2</code>
* @param String s
* The initial value of the string
* @return bool
*/
int opCmp(String s){
return std.string.cmp(cast(char[])this.value, cast(char[])s.value);
}
下面是测试
public static void main() {
String str = new String(" ...
import std.stdio;
interface I { abstract void f(); }
class X : I { void f() {writefln("Hello Interfac"c); } }
void main() {
I i = new X;
X x = cast(X)(i);
x.f();
}
抽象类
abstract class ab_class { //定义抽象类
void test1();
void test2();
}
class imp : ab_class {//实现抽象类,相当于java的implements
void test1() { printf("test1\n"); }
void test2() { printf("test2\n"); }
}
int main(){
ab_class a = new imp;
a.test1(); //
}
String opAssign(wchar[] value) {
int size = value.length;
offset = 0;
count = size;
value = value;
return this;
}
终于找到了正确的写法
public static void main() {
String s1 = new String("abc");
s1="abc";
writefln(s1);
}
好高兴呀!
char[] toString(){
return cast(char[])std.utf.toUTF8(this.value);
}
使用方法
String s1 = new String("abc");
writefln(s1);
今天研究了一下dstring,了解到在D语言里面只有struct里面有opCall
而Class是没有这个方法的,所以String str="abc";看来没法实现了
就算有,实现的方法也是String str=String("abc");所以这个方法实现也就没有什么意义了
- 浏览: 14352 次
- 性别:


- 详细资料
搜索本博客
最新评论
-
py2exe越来越爽了
[size=large][size=medium]大家好,python新手。现遇 ...
-- by davidsun2008 -
DLang策略模式
我会尝试着把模式详尽剖析。不过能力有限,望大家多提宝贵意见。
-- by jinheking -
DLang策略模式
不错的理念,赞一个。 能详尽剖析就更好了
-- by DavidL -
DLang策略模式
可以像很多D项目一样,自己写一个all.d,在这里面import上所有的modu ...
-- by shawind -
DLang策略模式
引用module 怎么让我的程序做的像import std.stdio; 而不用 ...
-- by jinheking






评论排行榜