我不知道为什么会这样。我得到的错误如下:
Error 2 error LNK2019: unresolved external symbol "public: int __thiscall Graphics::GLMatrix::getColumnSize(void)" (?getColumnSize@GLMatrix@Graphics@@QAEHXZ) referenced in function _SDL_main C:\Users\holland\Documents\code\c++\projects\OpenGL_01\OpenGL_01\main.obj
Error 3 error LNK2019: unresolved external symbol "public: int __thiscall Graphics::GLMatrix::getRowSize(void)" (?getRowSize@GLMatrix@Graphics@@QAEHXZ) referenced in function _SDL_main C:\Users\holland\Documents\code\c++\projects\OpenGL_01\OpenGL_01\main.obj
Error 4 error LNK1120: 2 unresolved externals C:\Users\holland\Documents\code\c++\projects\OpenGL_01\Debug\OpenGL_01.exe
没有链接的是我的 Matrix 类中的getRowSize()
andgetColumnSize()
函数。我究竟做错了什么?
那么,我在这里做错了什么?我一直在寻找……寻找各种方式。
编码
头文件:
#ifndef GLMATRIX_H
#define GLMATRIX_H
#pragma once
#include <array>
namespace Graphics {
class GLMatrix
{
public:
GLMatrix(int sizeX, int sizeY);
~GLMatrix();
void allocMatrix();
void addColumnI(int row, int column, long item);
void revertRowsByColumns(); /*changes the formula of r * c to c * r*/
GLMatrix &operator *(float scalar); /*multiply by scalar*/
inline int getRowSize();
inline int getColumnSize();
private:
int _sizeX, _sizeY;
long** _pArray;
};
}
#endif //GLMATRIX_H
资源:
#include "GLMatrix.h"
namespace Graphics {
GLMatrix::GLMatrix(int sizeX, int sizeY)
{
_sizeX = sizeX;
_sizeY = sizeY;
}
GLMatrix::~GLMatrix()
{
delete _pArray;
}
void GLMatrix::addColumnI(int row, int column, long item) {
}
inline int GLMatrix::getRowSize() {
return _sizeX;
}
inline int GLMatrix::getColumnSize() {
return _sizeY;
}
void GLMatrix::allocMatrix() {
_pArray = new long*[_sizeX];
for (int i = 0; i < _sizeX; ++i) {
_pArray[i] = new long[_sizeY];
}
}
void GLMatrix::revertRowsByColumns() {
long** columns = new long*[_sizeY];
for (int col = 0; col < _sizeY; ++col) {
columns[col] = new long[_sizeX];
memmove(
columns + col,
_pArray[_sizeX - col],
sizeof(_sizeX) - sizeof(col)
);
}
}
}
主要的:
#include <SDL.h>
#include "GLMatrix.h"
int main(int argc, char* argv[]) {
//SDL_Init(SDL_INIT_EVERYTHING);
//matrix test
Graphics::GLMatrix* matrix = new Graphics::GLMatrix(3, 3);
int num_rows = matrix->getRowSize();
int num_columns = matrix->getColumnSize();
for (int row = 0; row < num_rows; ++row) {
}
//SDL_Quit();
delete matrix;
return 0;
}