How does this class use constructor that references blink without an include statement

Please see class here:

https://bitbucket.org/chromiumembedded/cef/src/95973a7c1db47df0fa07fd453d0e5250c0e0f66c/libcef/renderer/frame_impl.h?at=master&fileviewer=file-view-default

The following namespace is used:

1
2
3
namespace blink {
class WebFrame;
}


How are they able to reference blink in the constructor's arguments without an include:

1
2
CefFrameImpl(CefBrowserImpl* browser,
               blink::WebFrame* frame);

Last edited on
The lines
1
2
3
namespace blink {
class WebFrame;
}
are a forward declaration. They are telling the code that there is a class called Webframe in the blink namespace.

The line CefFrameImpl(CefBrowserImpl* browser, blink::WebFrame* frame); says that we need a pointer to one of these Webframe objects. The compiler knows how big a pointer is, so it can allocate the memory for it. It knows that there is something called a Webframe, but since the pointer is never dereferenced in this code, it doesn't need to know what a Webframe is or what it does.

Code that dereferences the pointer needs to have the header file that defines the Webframe class. But code that only sees pointers and references can get away with a forward declaration.

I think there may be even a little bit more latitude than that in the arguments of function declarations, but this is the underlying reason.
okay, to be sure I understand.

The namespace could have been named anything but in this case the developer chose to use blink. it could have been

1
2
3
namespace blinksignal {
class WebFrame;
}


CefFrameImpl(CefBrowserImpl* browser, blinksignal::WebFrame* frame);

correct?

If the pointer were dereferenced and the user wanted to access data from the WebFrame class, would that mean that an include file would be needed? (included WebFrame.h on line 88)
Such as in the following implementation file.

https://bitbucket.org/chromiumembedded/cef/src/95973a7c1db47df0fa07fd453d0e5250c0e0f66c/libcef/renderer/content_renderer_client.cc?at=master&fileviewer=file-view-default
The namespace could have been named anything but in this case the developer chose to use blink. it could have been

No. The actual definition of the class would be still be in the blink namespace and you would run into linking issues.

If the pointer were dereferenced and the user wanted to access data from the WebFrame class, would that mean that an include file would be needed? (included WebFrame.h on line 88)

Yes. The definition is required anywhere such a pointer would be dereferenced.
that was very insightful answer. Where are namespaces defined in a program?

I assume it is similiar to a standard library namespace definition. I googled where standard library namespace was defined and it was said that it was so through several files. But there is a base standard library name and everyone is aware of it.

There must be something similar for the blink namespace. I will find it, just want clarification if my thinking is correct as far as how a namespace is defined.
Where are namespaces defined in a program?
Wherever the construct:

1
2
3
namespace {
    // stuff here
}


occurs.


There must be something similar for the blink namespace
I would imagine the namespace is used to segregate things in:
https://www.chromium.org/blink
Topic archived. No new replies allowed.