0

I was reading through VTK source files, I noticed statements as followed in some of the header files.

class vtkArray;
class VTKIOCORE_EXPORT vtkArrayWriter : public vtkWriter
{
    //Interface description here.
}

I was puzzled by the statement 'class vtkArray;'. What is the meaning of this statement? What is it being used for, when is a good time to use it?

This code is from a header file.

  • 3
    Look up `forward declaration`. http://stackoverflow.com/questions/4757565/c-forward-declaration – kmort Jan 02 '14 at 18:21
  • I would take issue with classifying my question as 'already answered'. Certainly, forward declarations is a concept that has been dealt with in detail here. But, introducing a concept and discovering the concept behind a particular concrete example are two different things. My question is an example of the latter, while the other posts are examples of the former. – Jean Claud Van Who Jan 02 '14 at 20:33
  • In addition to your point above, I think that it is useful to have, as you asked your question in a way that made sense to you. Future searchers might use the same vocabulary as you and if we remove this post, it will be harder for them to find the right info. I really dislike situations where you don't quite have the vocabulary to describe something nor search effectively. Finding the right vocabulary can help zero in on what you need to learn immensely. So don't worry about them closing it as "oh noes!!! already answered!!!" And welcome to Stack Overflow. :-) – kmort Jan 03 '14 at 03:41

3 Answers3

0

Is this in a header file? They are forward declaring the class vtkArray. This way they do not need to include the header file that contains that class. Then they can just include the header file in the .cpp file.

Edit: Link to explanation of forward declaration

Community
  • 1
  • 1
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
0

This looks like a forward declaration. http://en.wikipedia.org/wiki/Forward_declaration It is needed when you want to use a class before it is defined.

Andreas Vinter-Hviid
  • 1,482
  • 1
  • 11
  • 27
0

That is a forward declaration. It is mostly used when you need to declare the class type without specifying its internal form. This is useful when dealing with pointers or references as statements like:

type* x;
type& x;

does not require the compiler to know the size of type.

Shoe
  • 74,840
  • 36
  • 166
  • 272