這裏是一類,我開始頭:簡單的語法錯誤還是逃避我
#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
這裏是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;
}
而且我得到是錯誤的這些:
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
從我有限的經驗,他們看起來像簡單的語法錯誤,但我用我的生命,我什麼也看不見我錯過了。我知道把一個;在Canvas :: Canvas()的末尾是錯誤的,但這似乎是它所期望的。有人能爲我澄清嗎?
(另外,我知道很多的< <和>>操作定義看起來可怕,但除非是錯誤請不要解決這個問題的具體原因。這是一個草案:)代碼)
杜佩http://stackoverflow.com/questions/2646592/error-expected-before-token-what-is-the-cause熱賣同一用戶一個小時之前。 @melee - 不要這樣做 - 如果您有額外的信息,請編輯您的原始問題。 – 2010-04-15 19:20:56
你應該用任何新信息編輯你的舊問題,因爲這是相同的*問題*。 – GManNickG 2010-04-15 19:21:33
對不起。我今天註冊了這個網站,並且不太確定導航,找不到我原來的帖子。希望這不是太麻煩。 – user317654 2010-04-15 19:24:24