2013-02-24 34 views
4

在330頁從B.Stroustrup的獲得以下的「C++程序設計語言」第三版:作者用下面的僞代碼表示什麼?

template<class C> struct String<C>::Srep { 
    C* s; // pointer to elements 
    int sz; // number of elements 
    int n; // reference count 
    // ... 
}; 

template<class C> C String<C>::read(int i) const { return rep->s[i];} 

template<class C> String<C>::String() 
{ 
    p = new Srep(0, C()); 
} 

我對上面的構造函數的兩個問題:

1)不宜p替代通過rep

2)ctor Srep(0, C())應該如何在商店中構造一個Srep對象?

+0

可能是一個錯字:) – 2013-02-24 18:55:00

+1

已經有20+打印,在我的版本p是代表。 – 2013-02-24 18:55:12

+0

@Red Serpent但是構造函數調用'Srep(0,C())'呢? – WaldB 2013-02-24 18:56:11

回答

3

到1):是的。在我的書中我有以下代碼:

template<class C> struct String<C>::Srep { 
    C* s; // pointer to elements 
    int sz; // number of elements 
    int n; // reference count 
}; 

template<class C> C String<C>::read(int i) cont { return rep->s[i];} 

template<class C> String<C>::String<C>() 
{ 
    rep = new Srep(0, C()); 
} 
+0

您有哪些發行商/版本? – JBentley 2013-02-24 18:54:50

+1

這是同一版本,但德國。您也可以通過google找到此代碼,請參閱:http://books.google.de/books?id=3uhuFrKoyL8C&pg=PA352&lpg=PA352&dq=template%3Cclass+C%3E+struct+String%3Cc%3E :: SREP與源= BL&OTS = 49g3PcV52T與SIG = ST2hJCcvL1c6GzP3tIXR-wslr4w&HL = DE&SA = X&EI = 42AqUcCBLMSG4ASz54DQAg&VED = 0CDYQ6AEwAA#v = onepage&q =模板%3Cclass%20C%3E%20struct%20String%3CC%3E%3A%3ASrep&F =假 – duDE 2013-02-24 18:56:10

+0

@duDE任何有關評論我第二個問題? – WaldB 2013-02-24 18:57:46