读书人

error LNK2019 不得其解的有关问题

发布时间: 2012-03-15 11:50:39 作者: rapoo

error LNK2019 不得其解的问题
头文件:
#ifndef _ModelHandler_
#define _ModelHandler_

#include <vector>
#include <string>
#include "Model3D.h"

using namespace std;

class ModelHandler
{

private:
static Model3D *model3D;
static int argc;
static char** argv;
static int screenWidth; //屏幕的宽度
static int screenHeight; //屏幕的高度
static bool filling; //是否填充模型
static bool leftMouseDown; //鼠标左键是否按下
static bool middleMouseDown;
static bool rightMouseDown;
static int xPos; //鼠标相对于窗口的左边框的偏移量,以像素为单位
static int yPos; //鼠标相对于窗口上边框的偏移量,以像素为单位
static Polar polar;
static Point3D camera;

static vector<Point3D> newpoints ;

static const int RED=0, GREEN=1, BLUE=2, WHITE=3;
public:
ModelHandler(int argc, char **argv);
~ModelHandler();

static void set3DModel(string name, size_t num);
static void show3DModel();

static Model3D getmodel3d(){return *model3D;};
private:
static void init();
static void display();
static void resize(int width, int height);
static void keyboardHandler(unsigned char key, int x, int y);
static void keyboardSpecialHandler(int key, int x, int y);
static void mouseHandler(int button, int state, int x, int y);
static void mouseMoveHandler(int x, int y);
static void createGLUTMenus();
static void processMenuEvents(int option);

static void setCamera(Polar_Type x, Polar_Type y);
static void setPolarRadius(Polar_Type r);

//void drawRectangle(string &name, int x, int y, int thickness, int halfWidth);


//映射到三维图形上的点
Point3D get_3d_point(int x,int y);//传当前的坐标,若匹配不到点则返回空值
void addPoint(Point3D x);//加得到的点到集合
void show_newpoints();//在show3DModel();中调用,若存在添加的,则gl方式显示
};

#endif

CPP

#include <iostream>
#include <math.h>
#include <vector>
#include <windows.h>
#include <GL/glut.h>
#include "ModelHandler.h"

.....
void ModelHandler::display()
{
if(model3D == NULL)
{
return;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //清空颜色和深度缓存,为了绘制下一帧
glMatrixMode(GL_MODELVIEW); //模型变换
glLoadIdentity(); //初始化透视矩阵 as identity

//设定摄像机位置,所看到的景物将根据摄像机的位置改变而改变,这就是鼠标调整摄像机位置的结果
gluLookAt(camera.x, camera.y, camera.z,
0.0 , 0.0, 0.0, //这三个参数是摄像机观察的点
0.0, 2.0, 0.0); //这三个参数指定了视图的上方向

//glColor3f(red, green, blue); //菜单的响应
model3D->display3DModel();


int t=newpoints.empty();
if(t){
//display相应的点
}


glFlush(); //强制执行OpenGL的指令
glutSwapBuffers(); //在双缓冲模型,可视的缓存与写缓存交换
}
...

ModelHandler.obj : error LNK2019: 无法解析的外部符号 "private: static class std::vector<struct CvPoint3D32f,class std::allocator<struct CvPoint3D32f> > ModelHandler::newpoints" (?newpoints@ModelHandler@@0V?$vector@UCvPoint3D32f@@V?$allocator@UCvPoint3D32f@@@std@@@std@@A),该符号在函数 "private: static void __cdecl ModelHandler::display(void)" (?display@ModelHandler@@CAXXZ) 中被引用


第一次碰到这问题,请教帮看下怎么回事?

[解决办法]
static 成员变量需要在外部做个定义
[解决办法]
外部
ModelHandler::vector <Point3D> newpoints() ;

读书人网 >C++

热点推荐