7

I am a "C" programmer that knows just the tiniest bits of C++. I am having a look at some open source C++ code trying to understand some things that it is doing. I can work out most of it but sometimes there is syntax I don't recognise and I'd like to be able to "look up" the meaning of the syntax so I can read just enough to understand that bit of C++. But you can't just type a bunch of symbols into google - or whatever to find out the meaning in C++. Any suggestions of how I can do this in general?

The specific syntax I'm struggling with right now is the following:

void Blah<BOARD>::Generate(SgPoint p)

What is the significance of the <BOARD> in this context? What should I look up in order to understand it?

Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
Mick
  • 8,284
  • 22
  • 81
  • 173
  • 4
    C++ is a little bit non-trivial for this kind of approach. – Šimon Tóth Oct 05 '10 at 11:26
  • 5
    Actually, the easiest solution is what you just did: asking on SO. – ereOn Oct 05 '10 at 11:35
  • @ereOn: Well, the answer currently voted to the top came in 8mins after Mick posted his question. Add to this a few minutes to compose the question and a few more to wait which one will be voted to the top, and every time he's stuck he'll have to wait 15-20mins. How often, do you think, he needs to get stuck in order for the time to add up to be enough to skim through [Accelerated C++](http://stackoverflow.com/questions/388242/) and be able to understand most of what he comes across (not for being able to write such code, mind you) without asking? – sbi Oct 05 '10 at 11:40
  • @sbi: Of course asking should be the last ressort solution, when no other option exists. Reading and practicing are indeed much more efficient in the long run. – ereOn Oct 05 '10 at 12:46

4 Answers4

9

void Blah<BOARD>::Generate(SgPoint p)

Generate is a member function of a class template Blah .

BOARD is the name of the parameter.

Your class Blah could be like this :

template <typename BOARD>
class Blah
{
   //...some code
   void Generate(SgPoint p);
   //...some more code
};
Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
7

Blah is most likely a templated class, Generate is a method from this class and this is most likely the first line of the method definition.

Edit: Oh and BOARD is the template parameter (can be type or integral value).

Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
  • `` It's a _class template_. There's no template classes. – sbi Oct 05 '10 at 11:33
  • 1
    @sbi Your are right that it's not a template class. But that's not what I wrote. – Šimon Tóth Oct 05 '10 at 11:40
  • 2
    I'm sorry. In my defense I can say I'm correcting someone on this almost daily here. That's probably why my pattern matcher incorrectly pavloved on your answer... – sbi Oct 05 '10 at 13:12
5

This is the Generate method of the Blah class template specialized for template parameter BOARD.

In other words, what follows is the actual code that gets called when the Blah template is used to process an instance of class BOARD.

Other classes may get processed in a different way if separate specializations exist for them, or via the default non-specialized implementation of Generate, or not at all if there is no default and no specialization for them - in which case, an attempt to call that function will not compile.

There is a short introduction to the topic of template specialization here.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
  • 1
    Note that `BOARD` might be a template parameter, too, if Mick omitted the `template< typename BOARD >`. – sbi Oct 05 '10 at 11:35
3

You run into C++ templates - very neat feature!

phadej
  • 11,947
  • 41
  • 78