online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include "B.h" int main() { CA<double> myca_a(3); CA<double> myca_b(myca_a); CB<double> mycb_c(2, 3, 3.0); CB<double> mycb_d(3, 2, 4.0); CB<double> mycb_e; cout << "<separator>" << endl; cout << myca_a << endl; cout << "<separator>" << endl; cout << myca_b << endl; cout << "<separator>" << endl; cout << mycb_c << endl; cout << "<separator>" << endl; cout << mycb_d << endl; cout << "<separator>" << endl; cout << mycb_e << endl; cout << "<separator>" << endl; CB<double> myPrecious(mycb_c); return 0; }
#include "A.h" template <class DataType> class CB : public CA <CA <DataType> > { protected: CA < CA<DataType>* >* theRows; void copy(const CB<DataType>& m); void deleteRows(); public: CB(); CB(int n, int m); CB(int n, int m, DataType v); CB(const CB& a); virtual ~CB(); void operator= (const CB<DataType>& a); virtual int size() const; int columns(); int rows(); virtual CA<DataType>& operator[] (int index) const; friend ostream& operator<<(ostream& os, CB<DataType>& m) { int rows = m.rows(); int cols = m.columns(); os << "----------" << endl; for (int i = 0; i < rows-1; i++) { for (int j = 0; j < cols-1; j++) { os << m[i][j] << " "; } os << m[i][cols-1] << endl; } for (int j = 0; j < cols-1; j++) { os << m[rows-1][j] << " "; } os << m[rows-1][cols-1] << endl; os << "----------"; return os; } }; template <class DataType> CB<DataType>::CB() { theRows = new CA <CA <DataType>* >(1, NULL); (*theRows)[0] = new CA <DataType>(); } template <class DataType> CB<DataType>::CB(int n, int m) { theRows = new CA <CA <DataType>* >(n, NULL); for (int i = 0; i < n; i++) { (*theRows)[i] = NULL; (*theRows)[i] = new CA <DataType>(m); } } template <class DataType> CB<DataType>::CB(int n, int m, DataType v) { theRows = new CA <CA <DataType>* >(n, NULL); for (int i = 0; i < n; i++) { (*theRows)[i] = new CA <DataType>(m, v); } } template <class DataType> void CB<DataType>::deleteRows() { if (theRows != NULL) { for (int i = 0; i < theRows->size(); i++) { if ((*theRows)[i] != NULL) delete (*theRows)[i]; (*theRows)[i] = NULL; } delete theRows; } theRows = NULL; } template <class DataType> CB<DataType>::~CB() { deleteRows(); } template <class DataType> void CB<DataType>::copy(const CB<DataType>& m) { deleteRows(); theRows = new CA <CA <DataType>* >(m.size(), NULL); for (int i = 0; i < m.size(); i++) { (*theRows)[i] = new CA <DataType>(m[i]); } } template <class DataType> CB<DataType>::CB(const CB<DataType>& a) { deleteRows(); copy(a); } template <class DataType> void CB<DataType>::operator= (const CB<DataType>& a) { copy(a); } template <class DataType> int CB<DataType>::size() const { return theRows->size(); } template <class DataType> CA<DataType>& CB<DataType>::operator[] (int index) const { return (*(*theRows)[index]); } template <class DataType> int CB<DataType>::rows() { return theRows->size(); } template <class DataType> int CB<DataType>::columns() { return (*this)[0].size(); }
#include <iostream> using namespace std; template <class DataType> class CA { protected: DataType* paDataType; int _size; void copy(const CA<DataType>& ac); public: CA(); CA(int n); CA(int n, const DataType& o); CA(const CA<DataType>& ac); virtual ~CA(); int size() const; DataType& operator [] (int k); void operator= (const CA<DataType>& ac); friend ostream& operator<<(ostream& os, CA<DataType>& a) { os << "["; for (int i = 0; i < a.size() - 1; i++) os << a[i] << " "; os << a[a.size() - 1] << "]"; return os; } }; //Empty constructor template <class DataType> CA<DataType>::CA() { paDataType = new DataType[1]; _size = 1; } //Constructor template <class DataType> CA<DataType>::CA(int n) { paDataType = new DataType[n]; _size = n; } //Constructor w/ value template <class DataType> CA<DataType>::CA(int n, const DataType& o) { paDataType = new DataType[n]; _size = n; for (int i = 0; i < _size; i++) paDataType[i] = o; } //Copy Constructor template <class DataType> CA<DataType>::CA(const CA<DataType>& ac) { copy(ac); } //Copy method template <class DataType> void CA<DataType>::copy(const CA<DataType>& ac) { paDataType = new DataType[ac._size]; _size = ac._size; for (int i = 0; i < _size; i++) paDataType[i] = ac.paDataType[i]; } //Destructor template<class DataType> CA<DataType>::~CA() { if (paDataType != NULL) delete[] paDataType; paDataType = NULL; _size = 0; } //Size method template <class DataType> int CA<DataType>::size() const { return _size; } //Accessor template <class DataType> DataType& CA<DataType>::operator [] (int k) { return paDataType[k]; } //Overloaded assignment operator template <class DataType> void CA<DataType>::operator= (const CA<DataType>& ac) { if (paDataType != NULL) delete[] paDataType; copy(ac); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue