return CTypedPtrArray

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

return CTypedPtrArray

Post by mesajflaviu » 17 Dec 2014, 16:23

Am o situatie urmatoare:

Code: Select all

class CMyClass : public COtherClass
{
///
///
protected:
	class CHighlightCell : public CObject
	{
    // Attributes
	public:
		int m_nRow, m_nCol;
    // Implementation
	public:
		CHighlightCell();
		CHighlightCell(int nRow, int nCol);
		virtual ~CHighlightCell();
	};
	CTypedPtrArray<CPtrArray, CHighlightCell*> m_HighlightCell;

// Attributes
public:
	CTypedPtrArray& GetHighlightCells() const {return m_HighlightCell;}

};
la randul:

Code: Select all

CTypedPtrArray& GetHighlightCells() const {return m_HighlightCell;}
am eroare: error C2955: 'CTypedPtrArray' : use of class template requires template argument list
daca fac asa

Code: Select all

CTypedPtrArray* GetHighlightCells(){return &m_HighlightCell;}
am eroarea: error C2955: 'CTypedPtrArray' : use of class template requires template argument list
intrebarea mea este: as putea returna m_HighlightCell cumva ?
Multumesc anticipat.



User avatar
bu7ch3r
Membru++
Membru++
Posts: 326
Joined: 17 May 2011, 15:17
Judet: Iaşi
Location: Sofia
Contact:

Re: return CTypedPtrArray

Post by bu7ch3r » 18 Dec 2014, 13:21

Code: Select all

CTypedPtrArray<CPtrArray, CHighlightCell*>& GetHighlightCells()....
sau il pui in typedef:

Code: Select all

typedef CTypedPtrArray<CPtrArray, CHighlightCell*> theItem; 
theItem& Get..() const{..}
sau ii dai cu auto: auto GetHighlightCells() const { return whatever};

Compilatorul nu ghiceste in stele, CTypedPTrArray ala e:
template< class BASE_CLASS, class TYPE >
class CTypedPtrArray : public BASE_CLASS

Gandeste-te ca la std::list<int> getMyList() - pui tipul elementelor din lista nu lasi doar std::list getMYList();
Cu stima,
Lupu Claudiu

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: return CTypedPtrArray

Post by mesajflaviu » 18 Dec 2014, 20:51

Multumesc, o sa incerc solutia data de tine, dar cred ca voi reveni aici doar la anu' ... Numai bine !

mesajflaviu
Membru++
Membru++
Posts: 684
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: return CTypedPtrArray

Post by mesajflaviu » 05 Jan 2015, 12:22

Da, merge brici ! Multumesc.

Post Reply