Simple syntax error still eluding me.

Posted by melee on Stack Overflow See other posts from Stack Overflow or by melee
Published on 2010-04-15T19:18:34Z Indexed on 2010/04/15 19:23 UTC
Read the original article Hit count: 258

Filed under:
|
|

Here is the header for a class I started:

#ifndef CANVAS_
#define CANVAS_

#include <iostream>
#include <iomanip>
#include <string>
#include <stack>

class Canvas
{
  public:

  Canvas();
  void Paint(int R, int C, char Color);
  const int Nrow;
  const int Ncol;
  string Title;
  int image[][100];
  stack<int> path;
  struct PixelCoordinates
   {
    unsigned int r;
    unsigned int c;
   } position;
   Canvas operator<< (const Canvas& One );
  Canvas operator>>( Canvas& One );
};

/*-----------------------------------------------------------------------------
   Name:      operator<<
   Purpose:   Put a Canvas into an output stream
-----------------------------------------------------------------------------*/
ostream& operator<<( ostream& Out, const Canvas& One )
{
  Out << One.Title << endl;
  Out << "Rows: " << One.Nrow << "    Columns: " << One.Ncol << endl;
   int i,j;
   for( i=0; i<One.Nrow; i++)
   {
     cout<<"\n\n\n";
     cout<< " COLUMN\n";
     cout<< " 1 2 3";
     for(i=0;i<One.Nrow;i++)
     {
       cout<<"\nROW "<<i+1;
          for(j=0;j<One.Ncol;j++) cout<< One.image[i][j];
     }
   }

  return Out;
}

/*-----------------------------------------------------------------------------
   Name:      operator>>
   Purpose:   Get a Canvas from an input stream
-----------------------------------------------------------------------------*/

istream& operator>>( istream& In, Canvas& One )
{
//  string Line;
//  int Place = 0;

//  {
//    In >> Line;

//    if (In.good())
//    {
//      One.image[Place][0] = Line;
//      Place++;
//    }
//  return In;

#endif

Here is my implementation file for class Canvas:

using namespace std;
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include "proj05.canvas.h"

//----------------Constructor----------------//

Canvas::Canvas()
{
  Title = "";
  Nrow = 0;
  Ncol = 0;
  image[][100] = {};
  position.r = 0;
  position.c = 0;
}

//-------------------Paint------------------//
void Canvas::Paint(int R, int C, char Color)
{
  cout << "Paint to be implemented" << endl;
}

And the errors I'm getting are these:

proj05.canvas.cpp: In function 'std::istream& operator>>(std::istream&, Canvas&)':
proj05.canvas.cpp:11: error: expected `;' before '{' token
proj05.canvas.cpp:24: error: expected `}' at end of input

From my limited experience, they look like simple syntax errors but for the life of me, I cannot see what I am missing. I know putting a ; at the end of Canvas::Canvas() is wrong but that seems to be what it expects. Could someone please clarify for me?

(Also, I know much of the code for the << and >> operator definitions look terrible, but unless that is the specific reason for the error please do not address it. This is a draft :) )

© Stack Overflow or respective owner

Related posts about c++

Related posts about syntax