Octree and Node constructor for Triangle& pointer to reference error

Introduction

Hello i am a first time poster long time lurker of c++.
I recently started again on my gfx programming training and decided i would challenge myself with making a simple triangle octree.
After browsing google and finding few references on git and other sources to octrees with nodes using pointers but none with triangles i wanted to make one so i could understand it better and improve myself.

Sources i used and found:
https://github.com/charleslockner/GeneralizedOctree
https://www.flipcode.com/archives/Octree_Implementation.shtml
https://www.flipcode.com/archives/Introduction_To_Octrees.shtml
https://github.com/mwarning/SimpleOctree
http://nomis80.org/code/octree.html

Problem description
I created a Octree and Node class but i receive 56 errors related to

Pointer to reference is illegal
const_pointer pointer to reference is illegal
abstract declaration pointer to reference is illegal
...
In short every pointer to reference is illegal error i can receive.
All errors point to either std::vector or xmemory().

What i believe is that the compiler does not like Node* parent and rootNode since they are not objects in the class they are pointers and not objects, I tested with using const Node& and Node but ran in to a similar problem for some reason there is still a pointer to reference violation.

What i am trying to do
I am trying to creating a Octree with a bounding box around a model. I have the min , max values and i want my Octree constructor to create the first Node the rootNode with no parent Node. However if i use Node* i get pointer to reference is not allowed, and if i modify that to const Node& i am stuck since i cannot pass a nullptr or NULL to my Node constructor.

The rootNode is on line 97 of Octree.h in the Octree class, and parent on line 80 in same header but in Node class. From line 23 to 54 is just different types of constructors with member initialization when testing out different ways to get around this with same results.

What i would like
-Code review
-Tips on creating a Triangle Octree
-Help or guidance to get things rolling.
-Any material or something that i could use as a foundation on my journey



Octree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "stdafx.h"
#include "octree.h"
#include "vector3.h"
#include "triangle.h"
#include "model.h"


Node::Node(Node* parent, const Vector3& minBound, const Vector3& maxBound)
{
	this->parent = parent;
	this->minBound = minBound;
	this->maxBound = maxBound;
	this->center = Vector3
	(
		(minBound[0] + maxBound[0]) / 2.0f,
		(minBound[1] + maxBound[1]) / 2.0f,
		(minBound[2] + maxBound[2]) / 2.0f
	);

	Logger::message(" I AM BORN A NODE");
};
Node::~Node() {  };


Octree::Octree(const Vector3 &minBound, const Vector3 &maxBound, unsigned int maxDepth)
{	
	Node rootNode = Node(nullptr,minBound, maxBound);
	this->maxDepth = maxDepth;
	Logger::message(" I AM BORN A OCTREE");


};




Octree.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#ifndef __OCTREE_H__
#define __OCTREE_H__
#include "stdafx.h"
#include "vector3.h"
#include "triangle.h"
#include "model.h"





//class Node;

class Node {

public:

	//Different test constructors

	/*Node() :parent(parent), minBound(minBound), maxBound(maxBound) {};
	Node(const Node* a);*/
	
	/*Node(
		const Node& copy
	) :parent(copy.parent), minBound(copy.minBound), maxBound(copy.maxBound) {};
	
	inline const Node& Node::setTo(const Node& n) {
		return *this = n;
	}


	inline const Node& Node::setTo(const Node* n) {
		return *this = *n;
	}

	inline const Node Node::operator=(const Node n) {
		this->parent = n.parent;
		this->minBound = n.minBound;
		this->maxBound = n.maxBound;
		return *this;
	}	


	const Node& setTo(const Node& n) {
		if (this == &n)
			return *this;

	};
	const Node& setTo(const Node* n) {

	};
	*/


	inline Node* Node::operator=(Node* n) {
		if (this == n)
			return this;
	};

	Node(
		Node* parent,
		const Vector3& minBound,
		const Vector3& maxBound
	);

	~Node();

	

	

	
	
		Vector3 minBound;
		Vector3 maxBound;
		Vector3 center;
		Node* parent;
		std::vector<const Node& > subNodes;
		std::vector<const Triangle&> triangles;

};



class Octree {
	public:
		Octree(
			const Vector3 &minBound,
			const Vector3 &maxBound,
			unsigned int maxDepth
		) ;
		~Octree();
		
		Node * rootNode;
		
private:
		Node* node;
		unsigned int maxDepth;
};


*Edit tried to format the text and descriptions better
*Clarified a bit on problem and where i would need help.
Last edited on
The problem was fixed:

std::vector<const Node& > subNodes;
std::vector<const Triangle&> triangles;

For some reason this causes a pointer to reference error and commeting them out leads to fixing the errors and now the code compiles.
ya i didnt notice it at first changed them to vector<Triangle> and vector<Node*> and fixed it all.
Registered users can post here. Sign in or register to post.