vc++运行时错误

run time error in vc ++

本文关键字:运行时错误 vc++      更新时间:2023-10-16

我的项目包含几个类(其中一个是Point3D) &a cpp (CreatePoint.cpp) &头文件(CreatePoint.h).

我的stdafx.h文件是

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>

// TODO: reference additional headers your program requires here
#include "CreatePoint.h"
#include "Point3D.h"
#include "Vector3D.h"
#include "Sys.h"

my CreatePoint.h file is

#include "stdafx.h"
#pragma once
#include "Point3D.h"

//*******************************************************************
void initialise();
//*******************************************************************
Point3D *get_point(int);
//*******************************************************************
int get_index(Point3D *);
//*******************************************************************
Point3D *create_point();
//*******************************************************************
void del_point(Point3D *);
//*******************************************************************
void destruct_point();

我的CreatePoint.cpp文件

#include "stdafx.h"
#include "CreatePoint.h"
int counter;
int size = 50;
Point3D *point[];
//*******************************************************************
void initialise()//run this func each time point[] is created
{
    counter = 0;
    for(int i = 0; i<size; i++)
    {
    point[i] = '';
}
}
//*******************************************************************
Point3D *get_point(int index)
{
    return point[index];
}
//*******************************************************************
int get_index(Point3D *p)
{
    for(int i = 0; i<size; i++)
{
    if(point[i] == p)
        return i;
}
}
//*******************************************************************
Point3D *create_point()
{
point[counter] = new Point3D;
counter++;
return point[counter];
}
//*******************************************************************
void del_point(Point3D *p)
{
int d = get_index(p);
delete point[d];
}
//*******************************************************************
void destruct_point()
{
delete [] point;
}

我得到一个运行时错误:

CreatePoint.obj : error LNK2001: unresolved external symbol "class Point3D * * point" (?point@@3PAPAVPoint3D@@A)
1>C:Documents and Settingsmy documentsvisual studio 2010ProjectsMathsDebugMaths.exe : fatal error LNK1120: 1 unresolved externals

我已经搜索了网页& &;这种失败的主要原因是没有在每个文件的第一行包含stdafx.h…但是我已经把它包括进去了。我也得到一些警告的最后一个函数destruct_point() ->

mathsmathscreatepoint.cpp(51): warning C4154: deletion of an array expression; conversion to pointer supplied

LNK2001是一个链接器错误,而不是运行时错误。

Point3D *point[];似乎是一个声明,而不是实例化。也就是说,这一行告诉编译器这个变量将在稍后的某个地方存在。因为数组必须有一个要实例化的大小。(我甚至不知道[]在这个作用域中可以没有大小)

将其更改为Point3D *point[size];,它将实际创建数组。另外,size必须是const int

[编辑]
destruct_point()尝试删除整个点数组。由于数组是静态分配的,所以不允许这样做。既然你已经有了一个删除单个点的函数,我无法想象为什么这个函数存在。因为数组不是用new[]声明的,所以你不应该在它上面使用delete[]