Ubuntu 13.04 64 비트에서 DMD64 D 컴파일러 v2.063.2를 사용하고 있습니다. 클래스가이 방식으로 작성되어 있지만, 주요 기능에, 내가 그 코드를 작성 writeln이 없을 때 생성자가 없습니다.
class FixedList(T){
// list
private T[] list;
// number of items
private size_t numberOfItems;
// capacity
private size_t capacity;
// mutex
private Mutex listMutex;
// get capacity
@property public size_t Capacity(){ return capacity; }
@property public shared size_t Capacity(){ return capacity; }
// constructor
public this(size_t capacity){
// initialise
numberOfItems = 0;
this.capacity = capacity;
writeln("Cons Normal");
}
// constructor
public shared this(size_t capacity){
// initialise
numberOfItems = 0;
this.capacity = capacity;
// create mutex
listMutex = cast(shared)(new Mutex());
writeln("Cons Shared");
}
}
:이와
auto list1 = new shared FixedList!int(128);
auto list2 = new FixedList!int(128);
출력이, 아니이 나는 아래와 같은 클래스를 작성했습니다
모든 출력에서 오류는 다음과 같습니다 :
는Cons Shared
Cons Normal
내가 다음에 할 것은 모두을 제거하는 것입니다 658,113,210 코드에서 선 및 I 코드를 컴파일 할 때, 아래와 같은 에러 메시지를 나타내는 시작한다 :
src/webapp.d(61): Error: constructor lists.FixedList!(int).FixedList.this called with argument types:
((int) shared)
matches both:
lists.d(28): lists.FixedList!(int).FixedList.this(ulong capacity)
and:
lists.d(37): lists.FixedList!(int).FixedList.this(ulong capacity)
src/app.d(61): Error: no constructor for FixedList
src/app.d(62): Error: constructor lists.FixedList!(int).FixedList.this called with argument types:
((int))
matches both:
lists.d(28): lists.FixedList!(int).FixedList.this(ulong capacity)
and:
lists.d(37): lists.FixedList!(int).FixedList.this(ulong capacity)
src/app.d(62): Error: no constructor for FixedList
make: *** [all] Error 1
기본적 writeln
함수는 에러를 방지한다. 실제로 writeln
은 많은 곳에서 예방하고 있으며 왜 이런 일이 일어나고 있는지 확실하지 않습니다.
심지어는 m32
플래그를 사용하여 32 비트 용으로 컴파일하려고 시도했지만 여전히 동일합니다. 내가 잘못했거나 버그입니까?
코드에 무엇이 잘못되었는지 언급 할 수 있습니까? – NREZ
흠. 전자가 공유 객체를 만들려고 할 때, 특히 공유 생성자가 선택되었을 때 나는 생각했다. 나는 문서에서 '순수한 함수'를 읽었지만 그것에 대해서는 아무 것도 발견하지 못했습니다. – tcak
@ user2587136 생성자에 대한 순도가 유추되지 않습니다. 그것은 템플릿 함수에 대해 추론되며, 전체 클래스는 템플릿 처리되므로 생성자는 템플릿 처리됩니다. –