.


:




:

































 

 

 

 


BoolStack< T, SIZE >::isEmpty () const




{

return m_pTop == m_Data;

}

 

//*****************************************************************************

 

//

template < typename T, int SIZE >

BoolStack< T, SIZE >::isFull () const

{

return (m_pTop - m_Data) == SIZE;

}

 

//*****************************************************************************

 

#endif // _STACK_FIXED_ARRAY_HPP_

 

 

, , , .

 

 

- . , , ..

 

- . . , , - CPP-. , , CPP-:

 

mytemplate.hpp

 

#ifndef _MYTEMPLATE_HPP_

#define _MYTEMPLATE_HPP_

 

//*****************************************************************************

 

template < typename T >

class MyTemplate

{

T * m_pData;

const int m_size;

public:

MyTemplate (int _size);

~MyTemplate ();
};

 

//*****************************************************************************

 

#endif // _MYTEMPLATE_HPP_

 

mytemplate.cpp

 

#include "mytemplate.hpp"

 

//*****************************************************************************

 

template < typename T >

MyTemplate< T >::MyTemplate (int _size)

: m_size(_size)

{

m_pData = new T[ m_size ];

}

 

//*****************************************************************************

 

template < typename T >

MyTemplate< T >::~MyTemplate ()

{

delete[] m_pData;

}

 

//*****************************************************************************

 

test.cpp

 

#include "mytemplate.hpp"

 

//*****************************************************************************

 

int main ()

{

MyTemplate< int > o(10);
}

 

//*****************************************************************************

 

, . - :

 

error LNK2019: unresolved external symbol "public: __thiscall MyTemplate<int>::~MyTemplate<int>(void)" (??1?$MyTemplate@H@@QAE@XZ) referenced in function _main

error LNK2019: unresolved external symbol "public: __thiscall MyTemplate<int>::MyTemplate<int>(int)" (??0?$MyTemplate@H@@QAE@H@Z) referenced in function _main

 

, . test.cpp mytemplate.cpp . . :

1. mytemplate.cpp , ( ).

2. test.cpp, mytemplate.hpp, () (). , , - .

3. , , .. , - .

 

. , . CPP- , -, .

 

(explicit instantiation). , CPP- . , , MyTemplate - int std::string. mytemplate.cpp :

 

template class MyTemplate< int >;

template class MyTemplate< std::string >;

 

, MyTemplate , , . , CPP-, .

 

, ++11 , CPP-:

 

extern template class MyTemplate< int >;

 

, , , , . , - CPP-, , , , .

 

, , , , . , . - .. .

 

++11 - export - , . .

 





:


: 2017-01-21; !; : 334 |


:

:

, .
==> ...

1495 - | 1262 -


© 2015-2024 lektsii.org - -

: 0.029 .