Page 1 of 1

return CTypedPtrArray

Posted: 17 Dec 2014, 16:23
by mesajflaviu
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.

Re: return CTypedPtrArray

Posted: 18 Dec 2014, 13:21
by bu7ch3r

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();

Re: return CTypedPtrArray

Posted: 18 Dec 2014, 20:51
by mesajflaviu
Multumesc, o sa incerc solutia data de tine, dar cred ca voi reveni aici doar la anu' ... Numai bine !

Re: return CTypedPtrArray

Posted: 05 Jan 2015, 12:22
by mesajflaviu
Da, merge brici ! Multumesc.