How to use TConstElementBoxIterator

Hello,
I am struggling to use TConstElementBoxIterator

My Octree declaration:

struct FVertex			 //Struct for the element
{
public:
	int32 ID;

	FVector A;
	FVector B;

	//Functions:
	FVertex()
	{
		A = FVector(0);
		B = FVector(0);
	}

	FVertex(FVector a, FVector b) : A(a), B(b) {}

    FBoxCenterAndExtent EdgeGetBoundingBox() const		//C++ wtf again !?
	{
		FBox box = FBox(ForceInit);			   
		box += A;
		box += B;
		return FBoxCenterAndExtent(box);
	}
};

struct FVertexOctreeSemantics
{
	enum { MaxElementsPerLeaf = 16 };
	enum { MinInclusiveElementsPerNode = 7 };
	enum { MaxNodeDepth = 12 };

	typedef TInlineAllocator<MaxElementsPerLeaf> ElementAllocator;

	FORCEINLINE static FBoxCenterAndExtent GetBoundingBox(const FVertex* Element)
	{
		return Element->EdgeGetBoundingBox();
	}

	FORCEINLINE static bool AreElementsEqual(const FVertex* A, const FVertex* B)
	{
		return A == B;
	}

	//Ignored for now.
	FORCEINLINE static void SetElementId(const FVertex* Element, int32 Id) { /*Element.ID = Id; */}
};

typedef TOctree<FVertex*, FVertexOctreeSemantics> FEdgeTree;

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/TOctree/TConstElementBoxIterator/index.html

	FVector Extents = FVector(Range);
	const FBoxCenterAndExtent OverLapBox = FBoxCenterAndExtent(Center, Extents);


	FEdgeTree::TConstElementBoxIterator iter = FEdgeTree::TConstElementBoxIterator<FEdgeTree::DefaultStackAllocator>(m_edgeTree.Get(), OverLapBox);

But C++ don’t love me :frowning:

Error:

1>C:\Users\Roma\Documents\Unreal    Projects\NordicWarriors\Source\NordicWarriors\Navigation\NavEdgeQuerry.cpp(34):    error C2955:    'TOctree::TConstElementBoxIterator':    use of class template requires    template argument list 1>  c:\program    files\epic    games\ue_4.16\engine\source\runtime\engine\public\GenericOctree.h(564):    note: see declaration of    'TOctree::TConstElementBoxIterator'    1>C:\Users\Roma\Documents\Unreal    Projects\NordicWarriors\Source\NordicWarriors\Navigation\NavEdgeQuerry.cpp(34):    error C2440: '': cannot convert from    'initializer list' to    'TOctree::TConstElementBoxIterator::DefaultStackAllocator>'    1>  C:\Users\Roma\Documents\Unreal    Projects\NordicWarriors\Source\NordicWarriors\Navigation\NavEdgeQuerry.cpp(34):    note: No constructor could take the    source type, or constructor overload    resolution was ambiguous    1>C:\Users\Roma\Documents\Unreal    Projects\NordicWarriors\Source\NordicWarriors\Navigation\NavEdgeQuerry.cpp(34):    error C2512:    'TOctree::TConstElementBoxIterator':    no appropriate default constructor    available

I tried this exact way

	for (FEdgeTree::TConstElementBoxIterator<FEdgeTree::DefaultStackAllocator> it(m_edgeTree.Get(), OverLapBox); it.HasPendingElements(); it.Advance())
	{
		
	}

Got those errors
1>C:\Users\Roma\Documents\Unreal Projects\NordicWarriors\Source\NordicWarriors\Navigation\NavEdgeQuerry.cpp(35): error C2664: ‘TOctree::TConstElementBoxIterator::DefaultStackAllocator>::TConstElementBoxIterator(TOctree::TConstElementBoxIterator::DefaultStackAllocator> &&)’: cannot convert argument 1 from ‘FEdgeTree *’ to ‘const TOctree &’
1> C:\Users\Roma\Documents\Unreal Projects\NordicWarriors\Source\NordicWarriors\Navigation\NavEdgeQuerry.cpp(35): note: Reason: cannot convert from ‘FEdgeTree *’ to ‘const TOctree’
1> C:\Users\Roma\Documents\Unreal Projects\NordicWarriors\Source\NordicWarriors\Navigation\NavEdgeQuerry.cpp(35): note: No constructor could take the source type, or constructor overload resolution was ambiguous

I updated the Q with my Octree declarations

Oh it worked in the end… C++ is so dumb it can not convert from * to & :frowning:
So I had to replace m_edgeTree.Get() with *m_edgeTree.Get() …

Quite a catch for C programmer :smiley:

Hey there, if you see the examples in the engine’s source code you can find examples like:

for (FNavigationOctree::TConstElementBoxIterator<FNavigationOctree::DefaultStackAllocator> It(*NavigationOctree, DebugBounds); It.HasPendingElements(); It.Advance())
		{
			const FNavigationOctreeElement& Element = It.GetCurrentElement();
}

What is that FEdgeTree?

I am interested in why you use an enum for a constant variable?

That’s great :slight_smile:

I am not really C++ programmer, I am mostly C/Objective C one.
I am not familiar with C++ compilers and I know that:

There’s a historical reason too when dealing with template metaprogramming. Some compilers could use values from an enum, but not a static const int to instantiate a class.

So I just would be on the safe side :stuck_out_tongue:

Also I do not trust certain types of compilers like MSVC++ they love to mess things around.
Sadly enough there is no viable ICC integration to UE4 :frowning: