Tag Archive for 'Class'

Clase Lista simple para C++

Tal como publiqué hace algunos días la Clase String Simple para C++ como un ejercicio de aprendizaje de C++, ahora estoy liberando una Clase Lista simple para C++.

La librería standard tiene una clase list. Pero, mientras se está aprendiendo, es una buena idea saber cómo poder desarrollar tu propia clase list.

Esa es la razón por la que hice la clase List. No está pensada para proyectos profesionales (para ellos, deberías utilizar la list de la librería standard), sino como una ayuda para aprender C++.

template <class TYPE>
class List
{
	/* ... */

public:
	//Construction and destruction
	List() { /* ... */ }
	~List() { /* ... */ }
	
	List(const List& rlList) { /* ... */ }
	
	//Assignment operator
	List& operator=(const List& rlList);

	//Information
	int Length() { /* ... */ }
	bool Empty() { /* ... */ }

	//Element managing
	int Add(TYPE& rtData);
	TYPE* Elem(int nPos);
	bool Delete(int nPos);
	void DeleteAll();
	
	//Search
	int Find(TYPE& rItem, int nStartAt = 0);

	//Operadores
	TYPE& operator[](int nPos) { /* ... */ }	//Elem
	int operator<<(TYPE& rdData) { /* ... */ }	//Add

protected:
	void FreeList();
	void Init() { /* ... */ }
};

//Output
template <class TYPE>
std::ostream& operator<<(std::ostream& oStream, List<TYPE>& rlList);

Seguir leyendo…

Incoming search terms for the article:

Clase String simple para C++

Todo programador de C++ sabe que la librería standard tiene una clase string. Pero, mientras se está aprendiendo, es una buena idea saber cómo poder desarrollar tu propia clase string.

Esa es la razón por la que hice la clase String. No está pensada para proyectos profesionales (para ellos, deberías utilizar la string de la librería standard), sino como una ayuda para aprender C++.

class String
{
	char *m_pszString;	//Allocated buffer
	int m_nAllocated;	//Allocated length

public:
	//Construction and destruction
	String() { /* ... */ }
	~String() { /* ... */ }

	//Copy constructors
	String(const char *pszString) { /* ... */ }
	String(const String& rsString) { /* ... */ }

	//Operators (assignment)
	String& operator=(const char *pszString);
	String& operator=(const String& rsString) { /* ... */ }

	//Operators (concatenation)
	String& operator+=(const char *pszString);
	String& operator+=(String& rsString) { /* ... */ }
	String operator+(String rsString);

	//Operators (comparison)
	bool operator<(String sString) { /* ... */ }
	bool operator<=(String sString) { /* ... */ }

	bool operator>(String sString) { /* ... */ }
	bool operator>=(String sString) { /* ... */ }

	bool operator==(String sString) { /* ... */ }
	bool operator!=(String sString) { /* ... */ }

	//Operations
	void Clear();
	String Lower() { /* ... */ }
	String Upper() { /* ... */ }

	//Information
	int Length() { /* ... */ }

	//Cast operators
	operator const char*() { /* ... */ }

protected:	//Helper functions
	/* ... */
};

//Output e input
std::ostream& operator<<(std::ostream& oStream, String& rsString);
std::istream& operator>>(std::istream& iStream, String& rsString);

Seguir leyendo…

Incoming search terms for the article: