Reputation: 35
I'm working with a rather large project and I came up on a statement, which I do not understand. It looks like this:
visitor::DFV< Outer > visitor( *this, this->graph(), this->store() );
I would give you more code but it's really huge and I can't really tell which parts are relevant to this. Interesting is, that I can't even find any function called visitor
in the structure DFV or it's predecessors and neither does Eclipse. I'm pretty sure I don't get the meaning of this right and I'm unable to find any reference to this c++ syntax. Can anyone explain to me in general the meaning of statements like this?
Type<SomeClass> foo(x, y);
Upvotes: 0
Views: 288
Reputation: 151
I don't think you really understand C++ very well if you don't get this syntax.
visitor::DFV< Outer > visitor( *this, this->graph(), this->store() );
I would interpret this as a function either a static function in the class visitor or a global function in the namespace visitor, thats all I can say with the code available. The <Outer>
part is the template argument of the function for example if I did a template like this
template<class T>
int someFunc<T>(T i, Tx)
{
//whatever operations in the function
}
Then when I want to call that function I just do this
int i = someFunc<int>(2, 3);
//alternatively
int x = someFunc<std::string>("Hello", "World");
*this
is a derefenced pointer to the class that is calling the function, this->graph()
is the return value of the method graph()
in the class thats calling this function, this->store()
is the same as graph but with the return value of store()
.
The second bit is instantiating a template class like this
template<class T>
class Type
{
public:
Type(T x, T y);
};
Upvotes: 0
Reputation: 56863
For your generic example of:
Type<SomeClass> foo(x, y);
It's a variable definition, where Type<SomeClass>
is the type of the variable, foo
is its name and the rest are the parameters passed to the class' constructor.
The class template Type
will have some constructor, found in its definition (usually in its header file) which looks like:
template< typename T >
class Type
{
public:
Type( int x, int y );
};
Upvotes: 0
Reputation: 258618
It's not a function call, but a variable definition, and the (...)
is the constructor parameter list.
Would it be more clear as
typedef visitor::DFV< Outer > Type;
//...
Type visitor(*this, this->graph(), this->store());
or
Type visitor(x, y, z);
Upvotes: 3