У меня есть класс Point3D в моем проекте.
чтобы создать объект Point3D, я добавил файл cpp и файл заголовка следующим образом:
CreatePoint.h
#include "stdafx.h"
#pragma once
#include "Point3D.h"
//*******************************************************************
int counter = 0;
int size = 50;
Point3D **point;
//*******************************************************************
void create_array(int);//this will be called in main & pass 50//this is the method to create an array of pointers to Point3D
//*******************************************************************
void resize();//this increases the size of array if size - 5 elements are filled & increases size by 25
//*******************************************************************
Point3D *get_point(int);//this returns the pointer according to the index
//*******************************************************************
int get_index(Point3D *);//this returns the index of a point
//*******************************************************************
void move_point(int, int);//this interchanges the memory locations of 2 points
//*******************************************************************
void del_point(Point3D *);//this makes NULL value to the passed point
//*******************************************************************
void destruct_point();//this is called when the program ends by me
и файл cpp:
#include "stdafx.h"
#include "CreatePoint.h"
//*******************************************************************
void create_array(int s)
{
point = new Point3D *[s];
for (int i = 0; i<s; i++)
{
point[i] = NULL;
}
}
//*******************************************************************
void resize()
{
Point3D **copy = new Point3D *[size];
for(int i = 0; i<size; i++)
{
copy[i] = point[i];
}
delete [] point;
size += 25;
create_array(size);
for(int i = 0; i<(size - 25); i++)
{
point[i] = copy[i];
}
delete [] copy;
}
//*******************************************************************
Point3D *get_point(int i)
{
if((size - counter) == 5)
resize();
return point[i];
}
//*******************************************************************
int get_index(Point3D *p)
{
for(int i = 0; i<size; i++)
{
if(point[i] == p)
return i;
}
return -1;
}
//*******************************************************************
void move_point(int a, int b)
{
Point3D *apt = get_point(a);
Point3D *bpt = get_point(b);
Point3D *t = new Point3D;
t = apt;
apt = bpt;
bpt = t;
delete t;
}
//*******************************************************************
void del_point(Point3D *p)
{
int d = get_index(p);
move_point(d, counter - 1);
point[counter - 1] = NULL;
}
//*******************************************************************
void destruct_point()
{
delete [] point;
point = NULL;
}
Я получаю некоторые ошибки связывания:
stdafx.obj : error LNK2005: "class Point3D * * point" (?point@@3PAPAVPoint3D@@A) already defined in CreatePoint.obj
1>stdafx.obj : error LNK2005: "int counter" (?counter@@3HA) already defined in CreatePoint.obj
1>stdafx.obj : error LNK2005: "int size" (?size@@3HA) already defined in CreatePoint.obj
1>C:\Documents and Settings\SUMIT & AMIT\my documents\visual studio 2010\Projects\Maths\Debug\Maths.exe : fatal error LNK1169: one or more multiply defined symbols found
Может кто-нибудь, пожалуйста, помогите мне!
Также, любые предложения по коду будут оценены :)
СПАСИБО ЛОТ ДЛЯ ЧТЕНИЯ МОЕЙ ПОЧТЫ