Kadir Can'ın yazdığı bir programda karakter dizileri ile ilgili hatalar var. İlk önce kodları görelim:
module helper;
import std.stdio;
class HtmlHelper
{
char[] content;
char[] head;
this(){
this.content="";
this.head="";
}
void htmlTags(){
content~="<html>\n"~content~"</html\n";
}
void headTags(){
content~="<head>\n"~head~"</head>\n";
}
void createTitle(dchar[] title){
head~="<title>"~title~"</title>";
}
void bodyPiece(){
content~="<body>\n"~content~"</body>\n";
}
void header(int level,string text){
switch(level){
case 1: content~="<h1>"~text~"</h1>\n"; break;
case 2: content~="<h2>"~text~"</h2>\n"; break;
case 3: content~="<h3>"~text~"</h3>\n"; break;
case 4: content~="<h4>"~text~"</h4>\n"; break;
case 5: content~="<h5>"~text~"</h5>\n"; break;
case 6: content~="<h1>"~text~"</h6>\n"; break;
default: ;
}
}
void downLine(){
content~="<br />\n";
}
void paragraph(string metin){
content~="<p>"~metin~"</p>\n";
}
void bolder(string metin){
content~="<b>"~metin~"</b>\n";
}
void createTable(){
content~="<table>";
}
}
void main()
{
HtmlHelper help=new HtmlHelper();
help.downLine();
help.header(1,"Merhaba");
help.paragraph("Merhaba");
help.bolder("Merhaba");
help.bodyPiece();
help.createTitle("Merhaba");
help.head();
help.htmlTags();
}
Hata kodu:
htmlHelper.d(11): Error: cannot implicitly convert expression ("") of type string to char[]
htmlHelper.d(12): Error: cannot implicitly convert expression ("") of type string to char[]
htmlHelper.d(30): Error: cannot append type dchar[] to type char[]
htmlHelper.d(89): Error: function helper.HtmlHelper.createTitle (dchar[] title) is not callable using argument types (string)
htmlHelper.d(89): Error: cannot implicitly convert expression ("Merhaba") of type string to dchar[]
htmlHelper.d(90): Error: function expected before (), not help.head of type char[]
Hatanın yanıtını alt mesajlarda arayacağız.
--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]