搞亂如果我在一個.cpp文件中把這個代碼並運行它,它運行得很好:載體的C++向量與我
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef vector<int> row;
typedef vector<row> myMatrix;
void main()
{
//cout << endl << "test" << endl;
myMatrix mat(2,2);
mat[0][1] = 2;
cout << endl << mat[0][1] << endl;
}
但是,如果我做的.h和.cpp文件與這樣的.h文件,它給我船錯誤。
#ifndef _grid_
#define _grid_
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef vector<int> row;
typedef vector<row> myMatrix;
class grid
{
public:
grid();
~grid();
int getElement(unsigned int ri, unsigned int ci);
bool setElement(unsigned int ri, unsigned int ci, unsigned int value);
private:
myMatrix sudoku_(9,9);
};
#endif
這些都是一些我得到的錯誤:
warning C4091: 'typedef ' : ignored on left of 'int' when no variable is declared
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
'main()'返回什麼類型?我會給你一個提示:它是'int',而不是'void'。 – 2010-04-27 04:19:38