0

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);
SirGlorg
  • 35
  • 6
  • 1
    The second one defines an object named `foo` of type `Type, initialized with the constructor that takes two arguments, `x` and `y`. – Pete Becker Mar 27 '13 at 22:18
  • 1
    Why are you working on 'a rather large project' without having a proper knowledge of the C++ syntax? I'd recommend you to read a [good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) first – Tom Knapen Mar 27 '13 at 22:27
  • Thanks, you've been very helpful. I was overwhelmed with the code and all the template usages with which I'm not that familiar and I lost track of the basics. Even though I was thinking about it the whole afternoon I found the answer myself 5mins after I posted the question and started to hit my head at a keyboard. – SirGlorg Mar 27 '13 at 22:44

3 Answers3

3

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);
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
0

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 );
};
Daniel Frey
  • 55,810
  • 13
  • 122
  • 180
  • Worth adding that the scope `visitor::` might refer to a either class or namespace called `visitor`. – Keith Mar 27 '13 at 22:32
0

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);
};
David Tr
  • 151
  • 2
  • 9
  • "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." it can't be either, what are you talking about? – Luchian Grigore Mar 27 '13 at 22:56
  • How can't it be? if you call a function like this `foo::bar()` that could be a function called bar in a namespace called foo or a static function in a class called foo. I don't see what is not to get? – David Tr Mar 27 '13 at 23:08
  • Yes, but you can't call a function *and* declare its type in the same statement. – Luchian Grigore Mar 28 '13 at 06:54