DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Oct 2005

    already defined error

    header file
    using namespace std;
    struct point
       long double x, y;
    point stack[100]; // the actual point stack array
    point Pivot, S[100];
    int TOS_ptr;// = 0;           // Top Of Stack pointer
    int Push(point p);
    int Pop(point *p);
    long double CrossProduct(point p0, point p1, point p2);
    int compare_points(const void *a, const void *b);
    int LocatePivot(point S[], int N);
    void Graham_Scan(point S[], int N);
    This problem is driving me crazy....
    the header file as shown when I include it in my project, it compiles fine. As soon as I include the cpp in to my project (even if the cpp was empty and had just the line #include "ConvexHull_Graham_Scan.h"), it than complains:

    error C2871: 'std' : a namespace with this name does not exist

    cpp file
    #include "ConvexHull_Graham_Scan.h"
    int Push(point p)
    	// pushes point p onto the stack
    	// if successful Push() returns 1
    	// on stack overflow Push() returns 0
    	if (TOS_ptr == 100) return(0);
    	stack[TOS_ptr++] = p;
    int Pop(point *p)
    	// pops a point off of the stack
    	// if successful Pop() returns 1
    	// on stack underflow Pop() returns 0
    	if (TOS_ptr == 0) return(0);
    	*p = stack[--TOS_ptr];
    long double CrossProduct(point p0, point p1, point p2)
    	// Computes the cross product (p1-p0)x(p2-p0). If p2 is to the left of the 
    	// line from p0 to p1 the result will be positive.
    	long double xprod;
    	xprod = (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
    int compare_points(const void *a, const void *b)
    	// Support function for qsort()
    	// a < b if a makes a smaller angle with Pivot than does b
    	long double xprod;
    	point *point_a, *point_b;
    	point_a = (point *)a;
    	point_b = (point *)b;
    	xprod = CrossProduct(Pivot, *point_a, *point_b);
    	if (xprod < 0)
    		return(+1);    // a > b
    	else if (xprod > 0)
    		return(-1);    // a < b
    	return(0);         // a = b
    int LocatePivot(point S[], int N)
    	// Find point with smallest y coordinate; if there is more
    	// than one select the one with the smallest x coordinate.
    	int i, ndx;
    	long double minx, miny;
    	// initialize minimum coordinates found so far
    	ndx  = 0;
    	minx = S[ndx].x;
    	miny = S[ndx].y;
    	// locate lowest point in set
    	for (i = 1; i < N; i++)
    	   if (S[i].y > miny) continue;
    	   //    found a candidate for a new pivot
    	   if (S[i].y < miny)
    		  ndx = i;
    		  miny = S[i].y;
    	   else if (S[i].x < minx)
    		  ndx = i;
    		  minx = S[i].x;
    	// all done - return index of pivot point
    void Graham_Scan(point S[], int N)
    	// This is the actual Graham scan algorithm. It is called after the pivot 
    	// point has been located and the rest of the points have been sorted by 
    	// their polar angle.
    	int i;
    	point p;
    	for (i = 3; i < N; i++)
    	   while (CrossProduct(stack[TOS_ptr-2], stack[TOS_ptr-1], S[i]) < 0)

    now if I remove using name space, it compiles as long as I don't have #include "ConvexHull_Graham_Scan.h" anywhere else.

    when I include this line in my main file, it now complains that:

    ConvexHull_Graham_Scan.obj : error LNK2005: "struct point * S" (?S@@3PAUpoint@@A) already defined in stressfilereader.obj
    ConvexHull_Graham_Scan.obj : error LNK2005: "int TOS_ptr" (?TOS_ptr@@3HA) already defined in stressfilereader.obj
    ConvexHull_Graham_Scan.obj : error LNK2005: "struct point * stack" (?stack@@3PAUpoint@@A) already defined in stressfilereader.obj
    ConvexHull_Graham_Scan.obj : error LNK2005: "struct point Pivot" (?Pivot@@3Upoint@@A) already defined in stressfilereader.obj

    is there something obvious that I'm not seeing? :confused:
    Last edited by rssmps; 05-31-2006 at 04:27 AM.

Similar Threads

  1. I can't link FreeImage to C#
    By mesh2005 in forum .NET
    Replies: 1
    Last Post: 03-06-2006, 08:16 AM
  2. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 03:53 AM
  3. Returning errors from SQL Server Stored Procs
    By Khalizan in forum VB Classic
    Replies: 1
    Last Post: 11-28-2001, 01:32 AM
  4. verify local admin
    By Patrick Comeau in forum VB Classic
    Replies: 6
    Last Post: 03-22-2001, 10:50 PM
  5. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 02:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.