在 java 中,构建器的 setter 方法可以返回构建器本身,以便可以链接调用,如下所示:
public class builder{
private String name;
private int age;
private char glyph;
public builder setName(String name){
this.name = name;
return this;
}
public builder setAge(int age){
this.age = age;
return this;
}
public builder setGlyph(char glyph){
this.glyph = glyph;
return this;
}
public static void main(String[] args){
builder b = new builder().setName("").setAge(10).setGlyph('%');
}
}
这在 C++ 中可能吗?