vc++运行时错误
run time error in vc ++
我的项目包含几个类(其中一个是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[]
。
相关文章:
- 删除指向指针的指针是运行时错误吗
- c++中的指针和运行时错误
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 对单向链表进行排序时出现运行时错误
- 为什么此代码存在运行时错误?
- 你能解释一下什么运行时错误是如何解决它的吗?
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 运行时错误:引用绑定到类型为"int"的空指针
- 为什么当 vector 为空时会显示运行时错误?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 运行时错误:矢量下标超出范围:正在检查空集
- 分配给gslice_array会导致运行时错误
- cout 新创建的对象引发运行时错误
- C++在使用std::multimap时出现运行时错误的几率很小
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- VC 中的运行时错误,但不在GCC中
- vc++运行时错误
- 激活上下文生成失败.VC运行时错误