neshaa 0 Newbie Poster

Hello, i'm having problem with this: I'm having binary square matrix, which i need to expand for given number (lets call it n). This should look like this- if dimension of matrix is 2x2 and n is 2. I should check which numer is in first matrix - if it's one, then new segment of new matrix (which dimension is nxn) is filled with 1s, same with 0.
starting matrix:
1 0
0 1
expanded
1 1 0 0
1 1 0 0
0 0 1 1
0 0 1 1
and i forgot, it must be done using operator++ (not binary one)
i've tryed do it this way, but program crashes:

KompresovanaSlika KompresovanaSlika::operator++()
	{
	    int	k=n1*ps;
		KompresovanaSlika nova(k);
		
		for (int i=0; i<n1; i++)
		{
			for (int j=0; j<n1; j++)
			{
				if (kmat[i][j] == 1)
				{
					for (int a =0; a*ps<k;++a)
					{
						for (int b=0; b*ps<k;++b)
						{
							for (int c=0; c<ps;++c)
							{
								for (int d=0; d<ps;++d)
									nova.kmat[a*ps+c][b*ps+d]=1;
							}
						}
					}
				}
				else
				{
					for (int a =0; a*ps<k;++a)
					{
						for (int b=0; b*ps<k;++b)
						{
							for (int c=0; c<ps;++c)
							{
								for (int d=0; d<ps;++d)
									nova.kmat[a*ps+c][b*ps+d]=0;
							}
						}
					}
				}
			}
		}
		n1=k;
		for (int i=0;i<n1;i++)
			for(int j=0;j<n1;j++)
				this->kmat[i][j]=nova.kmat[i][j];
		
	  return *this;