Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

New Developer
Posts: 26
Registered: ‎02-22-2013
My Device: BlackBerry Z10
My Carrier: Telus
Accepted Solution

Returning a Page to another class?

Simple question here: 


I have a class which contains my "main" nagivation pane (menu) for my app.


For anything that needs to be addded, I have other classes which do all the work (create page, add content, etc). From the main class, I have want to do: navigationPane->push(classB.createContent()), and createContent would return a Page object with all the stuff on it. 


If I set return type as Page, in my header file for classB like so:


// Page* getPage();


I get this error in the header file: error: 'Page' does not name a type.


Is there a way I can get this Page object which I created in classB to use in my main class, classA? I also tried using a static variable for the Page but that didn't work either...


Any help is appreciated, thanks.

Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Returning a Page to another class?

welcome to the support forums.

"does not name a type" looks like you did not have the correct includes.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Returning a Page to another class?

[ Edited ]



Forward-declare the Page in header file:

namespace bb { namespace cascades { class Page; } }


And use a fully-qualified name:

bb::cascades::Page *getPage();

Depending of what you're trying to do it might be better to create a class inheriting from Page and create the content in constructor.


Adding "using namespace bb::cascades" would also fix the error but it's not recommended to do this in header files.


Also headers shouldn't be included in other header files unless inheriting from these classes or instantiating them in-place. Pointers and references can be forward-declared. This will make the compilation faster.


Andrey Fidrya, @zmeyc on twitter
New Developer
Posts: 26
Registered: ‎02-22-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: Returning a Page to another class?

Thank you Zmey! The forward declaration worked very well! You saved me from a lot of trouble and time wasted googling!


Thanks again Smiley Happy