Thread: object array problems (some openGL but its pretty irrelevant to the problem)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    11

    object array problems (some openGL but its pretty irrelevant to the problem)

    I have this project im working on. It will eventually be an implementation of Dijkstra's shortest path algorithm using some c++ classes and openGL to visualize it.

    My problem is creating a data structure to hold an array of nodes that I can draw to the screen. Im sure there is something im missing, ive researched online for hours but I couldnt find anything that could help me with my problem. Here is the code thats giving me problems:

    Node is declared in a header file. Ill go ahead and include that whole file.
    "Node.h":
    Code:
    #include <GL/glut.h>
    #include <GL/glu.h>
    #include <GL/gl.h>
    
    class Node {
    	private: 
    		GLfloat x, y, z;
    		int numLinks;
    		Node *links[];
    	public: 
    		//Node(GLfloat x, GLfloat y, ...);
    		Node();
    		Node(GLfloat x, GLfloat y);
    		~Node();
    		GLfloat getNodeX();
    		GLfloat getNodeY();
    		GLfloat getNodeZ() {return 0.0f;}
    		GLvoid setNodeX(GLfloat x);
    		GLvoid setNodeY(GLfloat y);
    } Node;
    
    Node::Node() {
    	this->x = 0.0f;
    	this->y = 0.0f;
    	this->z = 0.0f;
    }
    
    Node::Node(GLfloat x, GLfloat y) {
    	this->x = x;
    	this->y = y;
    	this->z = 0.0f;	
    }
    
    /*Node::Node(GLfloat x, GLfloat y, int numLinks, ...) {
    	va_list arguments;
    	va_start(arguments, numLinks);
    	for (int i = 0; i < numLinks; i++) {
    		this.links[i] = va_arg(arguments, *Node);
    	}
    	this.x = x;
    	this.y = y;
    	this.z = 0.0f;	
    }*/
    
    GLfloat Node::getNodeX() {
    	return this->x;
    }
    
    GLfloat Node::getNodeY() {
    	return this->y;
    }
    
    GLvoid Node::setNodeX(GLfloat x) {
    	this->x = x;
    }
    
    GLvoid Node::setNodeY(GLfloat y) {
    	this->y = y;
    }
    
    Node::~Node() {
    }
    Global array:
    Code:
    Node *nodes[NUM_NODES];
    Code:
    int makeNodes() {
    	nodes[0] = new Node(0.0f, 0.0f);
    }
    g++ gives me these errors which correspond to the 4 lines above. The first error being the global variable.
    DijkstraShortestPath.cpp:11:1: error: ‘Node’ does not name a type
    DijkstraShortestPath.cpp: In function ‘int makeNodes()’:
    DijkstraShortestPath.cpp:58:2: error: ‘nodes’ was not declared in this scope
    DijkstraShortestPath.cpp:58:17: error: expected type-specifier before ‘Node’
    DijkstraShortestPath.cpp:58:17: error: expected ‘;’ before ‘Node’

    I would appreciate some suggestions on how to fix this, or even suggestions on a better way to keep track of my nodes.
    Last edited by wassat676; 07-12-2011 at 10:56 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-17-2006, 08:03 AM
  2. Clicking an Object in OpenGL.
    By gpr1me in forum Game Programming
    Replies: 5
    Last Post: 03-26-2006, 10:12 PM
  3. How to eliminate irrelevant conditionals?
    By cdave in forum C Programming
    Replies: 9
    Last Post: 12-10-2005, 04:39 PM
  4. Array of Pointers + Deleting An Object = Problems
    By Nereus in forum C++ Programming
    Replies: 3
    Last Post: 03-04-2004, 12:16 PM
  5. Irrelevant question?
    By f0ul in forum Linux Programming
    Replies: 25
    Last Post: 05-25-2002, 12:16 AM