C++ 什么';项目的适当文件结构是什么?

C++ 什么';项目的适当文件结构是什么?,c++,C++,我是OOP/C++新手。我有三个文件:main.cpp、matrix.cpp和matrix.h。我一直在犯错误,这很时髦 错误C2653:“矩阵”:不是类或命名空间名称 错误C2065:“坟墓”:未声明的标识符 main.cpp: #include "stdafx.h" #include "matrix.h" int _tmain(int argc, _TCHAR* argv[]) { matrix m; return 0; } 矩阵h: #ifndef MATRIX_H #

我是OOP/C++新手。我有三个文件:main.cpp、matrix.cpp和matrix.h。我一直在犯错误,这很时髦

错误C2653:“矩阵”:不是类或命名空间名称

错误C2065:“坟墓”:未声明的标识符

main.cpp:

#include "stdafx.h"
#include "matrix.h"

int _tmain(int argc, _TCHAR* argv[])
{
    matrix m;
    return 0;
}
矩阵h:

#ifndef MATRIX_H
#define MATRIX_H
class matrix{

private:
    int tomb[3][3];

public:
    matrix(); //default konstruktor


};

#endif
matrix.cpp

#include "matrix.h"
#include "stdafx.h"
#include <iostream>

matrix::matrix(){
    unsigned int x=0, y=0;

    for(unsigned int i = 0; i<9; i++){
        std::cout << "Kerem a(z) " << i << ". szamot" << std::endl;
        std::cin >> matrix::tomb[x][y];
        if(y<2) y++;
        else{
            y =0;
            x++;
        }
    }
}
#包括“matrix.h”
#包括“stdafx.h”
#包括
矩阵::矩阵(){
无符号整数x=0,y=0;

对于(无符号整数i=0;i
#包括“stdafx.h”
如果您使用的是预编译头,则需要将其作为第一个指令。之前的所有内容都会被忽略。@Peterhune出于好奇,您知道其背后的原因吗?@user2351645:注意,当x>=3时,您也在写超出坟墓界限的内容。对于x,最好有一个从(0,2)开始的循环和一个从(0,2)开始的内部循环(0,2]表示y(在坟墓声明和这些循环之间共享一些“最大维度”的符号表示)。此外,您应该研究使用std::vector或std:array。@EricFinn:当然,我怀疑它会忽略stdafx.h包含之前的所有内容,因为对预处理器状态的任何更改都可能会影响.pch。很可能编译器团队从未感到有必要至少检查包含之前是否有任何非注释标记如果存在,则返回d错误,而不是静默忽略它们。@Peter我很确定,如果MSVC在包含预编译头之前找到非注释标记,则会发出诊断: