tags:

views:

356

answers:

7

Here is my implementation file:

using namespace std;

#include <iostream>
#include <iomanip>
#include <string>
#include <stack>  //line 5
#include "proj05.canvas.h"

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

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

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

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:22: error: a function-definition is not 
    allowed here before '{' token
proj05.canvas.cpp:24: error: expected `}' at end of input
proj05.canvas.cpp:24: error: expected `}' at end of input

These seem like simple syntax errors, but I am not sure what's wrong. Could someone decode these for me? I'd really appreciate it, thanks for your time!


EDIT

Here is the definition of Canvas in my .h file:

#ifndef CANVAS_H 
#define CANVAS_H 

#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; 
}; 

#endif 
+7  A: 

"proj05.canvas.h" i bet the problem is there. may be no ; after class def

Andrey
Oh, you beat me by almost a minute :). That sounds like what it is
Michael Mrozek
Wouldn't it be great to have an error say 'hey, I think you may have missed a semicolon after your class definition' rather than that mess there?
tloach
@tloach Clang does exactly that: http://zi.fi/shots/clang.png
Michael Mrozek
comment removed
Michael Dorgan
@Michael: Why not just delete your comment?
GMan
+1  A: 

It sounds like you forgot to put a semicolon after your class definition. Look in "proj05.canvas.h". You should see something like:

  class Canvas{
    ...
  };
zipcodeman
+1  A: 

One thing that catches my eye as wrong/weird is image[][]. That does not really do anything. Also, I do not believe you can assign to constant member outside of a ctor list.

Finally, your assignment to PixelCoordinates is completely in error. You've created a local struct definition, but have not made a member that uses it, therefore you cannot assign anything at all to it - especially the struct's title. That would really confuse a compiler.

Michael Dorgan
You're right, I realize image[][] needs a bound for at least the second bracket...I should change that. thanks. :)
What exactly are you trying to do with that line?
Michael Dorgan
+2  A: 

Few things:

1

PixelCoordinates.r = 0;
PixelCoordinates.c = 0;

should be:

position.r = 0;
position.c = 0;

2

image has already been declared. What is this:

image[][];
codaddict
I changed PixelCoordinates.r and .c to be position.r and .c, like you said. I also changed image[][] to be image[][100] so it has a second bound, this is now identical between the two files. But it is not fixing my errors, it's quite confusing. Thanks for your input though, it is always appreciated. :)
A: 

Yikes.

(Not an answer to your specific problem, but...)

You should also remove the

using std;

That has no business in a .h file. I am going to guess the oddly formatted .h file may be a problem. It is legal for a filesystem of course, but it could be that. Also ensure you have the ending semicolon on the class.

You need to have both dimensions filled in for the array you have (probably a horrible design to use that int he class anyway...)

Tim
Is there a better data structure to use? I am trying to store a map of characters (the 'canvas') and a two-dimensional array seemed to be the only thing to use. If there is a cleaner way to store the data I would happily change it.
If you need a map then std::map should suffice. Do you mean map or a 2d array?
Tim
+6  A: 

You must use initializer list to initialize const-members

Try this:

#include <iostream>
#include <iomanip>
#include <string>
#include <stack>  //line 5
#include "proj05.canvas.h"

using namespace std;

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

Canvas::Canvas():Nrow(),Ncol() // Initializer list
{
  Title = "";
  //initialize image[][] correctly, your way is syntactically incorrect
  position.r = 0; //correction here
  position.c = 0; // and here
}

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

Whatever the reason for other errors is, the memeber definition int image[][100] is illegal. Non-static data members of the class cannot be declared with incomplete types. All dimensions of an array must be specified explicitly.

AndreyT