Project with multiple files
In this section we'll learn about C++ app development comprising of multiple files. We'll develop a class, called Vector
, which implements a dynamic array. This class is similar to the std::vector
class offered by Standard Template Library (STL) and has a very limited set of features compared to STL class.
Create a new project and name it App2
. Navigate to File | New | File… menu option and then choose C/C++ header option and follow the wizard to add a new file to App2
project. Add the following code in a new file under App2
and name it vector.h
file:
#ifndef __VECTOR_H__ #define __VECTOR_H__ #ifndef DATA_TYPE #define DATA_TYPE double #endif class Vector { public: Vector(size_t size = 2); virtual ~Vector(); size_t GetCount() const; bool Set(size_t id, DATA_TYPE data); DATA_TYPE operator[] (size_t id); private: DATA_TYPE* m_data; size_t m_size; }; #endif //__VECTOR_H__
Header file vector.h
declares the Vector
class structure....