错误LNK2019:无法解析的外部符号" public:__thiscall:构造函数问题 [英] error LNK2019: unresolved external symbol "public: __thiscall : constructor issue

查看:770
本文介绍了错误LNK2019:无法解析的外部符号" public:__thiscall:构造函数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试以下几行,但出现LNK2019错误,指向构造函数中的错误。如果将构造函数实现从源文件移到头文件,则可以正常工作...

I want to test the following lines but I get a LNK2019 error, pointing an error in my constructor. If the constructor implementation is moved from the source file to the header, it works...

dVector是std :: vector的typedef

dVector is a typedef of std::vector

错误LNK2019:未解决的外部符号 public:__thiscall Grid :: Grid(int,class std :: vector>& ;, class std :: vector>& ;, class std ::: vector>&)

//main.cpp
#include <Math/PDE/Grid.h>
#include <vector>
int main(){

dVector oLowerBounds(2);
dVector oUpperBounds(2);
int lNumberOfStates(2);
dVector oMArkovianStates(2);
std::vector<int> oGridSizes(2);
Grid * pGrid=  new Grid(lNumberOfStates, oLowerBounds, oUpperBounds, oGridSizes);
return 0;
}

// Grid.h

//Grid.h

#ifndef GRID_H
#define GRID_H
#pragma once

#include <Math/Matrix/Matrix.h>
#include<vector>

class Grid
{
public:

Grid(int inGridDimension,
     dVector &inLowerBounds,
     dVector &inUpperBounds,
     std::vector<int> &inGridSizes);

double getGridElement(int index1, int index2){return mGrid[index1][index2];};
void buildUniformGrid();
bool getIsUniformGrid(int index){return mIsUniformGrid[index];};
int getGridSize(int index);
~Grid(void);
private:
int mGridDimension;
std::vector<bool>   mIsUniformGrid;
std::vector<double> mLowerBounds;
std::vector<double> mUpperBounds;
std::vector<int> mGridSizes;
std::vector<std::vector<double>> mGrid;
};

#endif

// Grid.cpp

//Grid.cpp

#include <Math/PDE/Grid.h>



Grid::Grid(int inGridDimension,
std::vector<double> &inLowerBounds,
std::vector<double> &inUpperBounds,
std::vector<int> &inGridSizes):
mGridDimension(inGridDimension),
mLowerBounds(inLowerBounds),
mUpperBounds(inUpperBounds),
mGridSizes(inGridSizes)
{

}


Grid::~Grid(void)
{
}


推荐答案

问题似乎是存在两个项目

The problem seems to be the fact that there are two projects and one cannot find the compiled class of the other.

我将尝试解释在Visual Studio中将一个项目用作库,将一个项目用作应用程序的过程。

I will try to explain the procedure to use one project as library and one as application in Visual Studio.

首先在库项目中右键单击-> properties,然后在常规选项卡下,配置类型应为静态库(.lib)。

First in the library project do rightclick->properties, then under the tab General, Configuration Type should be Static library (.lib).

然后在应用程序项目中再次转到属性,选择链接器->输入,然后在其他库文本框中使用箭头选择编辑。然后在第一个项目的已创建库的完整或相对路径的底部(您可以首先构建它以验证位置)。

Then in the application project go to properties again, select Linker->Input and in the textbox Additional Libraries, use the arrow to select Edit. Then at the bottom at the full or relative path to the created library of the first project (You can first build it to verify the location).

这篇关于错误LNK2019:无法解析的外部符号&quot; public:__thiscall:构造函数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆