2013-09-03 34 views
5

Test durumda aşağıdaki gibi:Neden g ++, farklı adlandırma sistemlerine sahip iki kurucu üretir?

// test.cpp 
class X { 
public: 
    X(); 
}; 

X::X() { } 

void foo() { 
    X x; 
} 

Bu derleme ve bunun gibi nesne dosyasında semboller okuyun:

[[email protected] tmp]# g++ -c test.cpp 

[[email protected] tmp]# readelf -s -W test.o 

Sembol tablo '.symtab' 12 girdileri içerir:

Num: Değer Boyut Tür Bind Vis Ndx Adı

0: 0000000000000000  0 NOTYPE LOCAL DEFAULT UND 
1: 0000000000000000  0 FILE LOCAL DEFAULT ABS test.cpp 
2: 0000000000000000  0 SECTION LOCAL DEFAULT 1 
3: 0000000000000000  0 SECTION LOCAL DEFAULT 3 
4: 0000000000000000  0 SECTION LOCAL DEFAULT 4 
5: 0000000000000000  0 SECTION LOCAL DEFAULT 6 
6: 0000000000000000  0 SECTION LOCAL DEFAULT 7 
7: 0000000000000000  0 SECTION LOCAL DEFAULT 5 
8: 0000000000000000 10 FUNC GLOBAL DEFAULT 1 _ZN1XC2Ev => X::X() 
9: 0000000000000000  0 NOTYPE GLOBAL DEFAULT UND __gxx_personality_v0 
10: 0000000000000000 10 FUNC GLOBAL DEFAULT 1 _ZN1XC1Ev => X::X() 
11: 000000000000000a 22 FUNC GLOBAL DEFAULT 1 _Z3foov 

[[email protected] tmp]# c++filt _ZN1XC1Ev 

X::X() 

[[email protected] tmp]# c++filt _ZN1XC2Ev 

X::X() 

Neden g ++ Farklı adlandırma mandallarıyla iki kurucu oluştur (_ZN1XC1Ev ve _ZN1XC2Ev)?

+1

Bazı derleyiciler çağırmak için iki kullanıcı programlarından çağırmak inşaatçı, diğeri üretmek bakın Başka bir nesnenin sınıfı bazen yapılması gerekenler arasında bazı farklılıklar vardır. Ayrıntılarda biraz belirsizim ve buradaki durumun bile olup olmadığını bilmiyorum, bu tamamen yanlış olabilir ve bu yüzden bir cevap değil :) – jcoder

cevap

0

G ++ 'dan bilinen bir kusurdur. Eğer vektörlerin içine klonlanabilir ve dtors bu üç türleri hakkında daha fazla bilgi edinmek istiyorsanız, Known g++ bugs

 G++ emits two copies of constructors and destructors. 
    In general there are three types of constructors (and destructors). 

    1.The complete object constructor/destructor. 
    2.The base object constructor/destructor. 
    3.The allocating constructor/deallocating destructor. 

    The first two are different, when virtual base classes are involved. 

bakın bir üs olarak kullanıldığı zaman link

İlgili konular