1

I came across the following code in the OpenVDB documentation:

template<typename _RootNodeType>
class Tree: public TreeBase
{
...
    template<typename OtherTreeType>
    Tree(const OtherTreeType& other,
        const ValueType& inactiveValue,
        const ValueType& activeValue,
        TopologyCopy): // <-- this looks weird
        TreeBase(other),
        mRoot(other.root(), inactiveValue, activeValue, TopologyCopy())
    {
}

I've seen previously that an argument defaults to an int if no type is specified, but could this be the case here? TopologyCopy is being called as an operator 2 lines below.

What does the above declaration do/mean?

Edit: The accepted answer explains what is happening. The solution is to call the function as

openvdb::Tree newTree(oldTree, inactiveValue, activeValue, TopologyCopy());
Community
  • 1
  • 1
pingul
  • 3,351
  • 3
  • 25
  • 43
  • Looks weird because it IS weird. Why would someone take an argument, not use it, and default construct the same type?? I'd hope somewhere there's a comment as to why or an obvious reason that argument needs to be there to distinguish it from some other version of the constructor. – Edward Strange Jul 22 '16 at 00:00

2 Answers2

3

It's not an argument without a type. It's an argument without a name. Its type is TopologyCopy. And TopologyCopy() is default constructing an object of that type and passing it to the constructor of mRoot. If I had to guess, I would say they are probably using tag dispatching here to select between different constructors with otherwise identical arguments.

Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
0

TopologyCopy is a type, and as the argument/variable is not used, it is not present.

Following TopologyCopy() constructs a TopologyCopy.

Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • You can't really *call* a constructor as a user, since constructors don't have a name. And imagine `using TopologyCopy = int;` – Kerrek SB Jul 22 '16 at 00:00