Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

pimpl + namespaces

Posted on 2010-09-05
5
Medium Priority
?
392 Views
Last Modified: 2012-06-22
Hi,

I have problem with pimpl idiom used with namespaces

 
--file1--
namespace space_a {
namespace implementation {

class Impl
{
 public:
 Impl();
 void test();
};

}}


--file2--
#include file1

namespace space_a {

class A
{
 public:
 A(); 
 private:
 // here impl declaration *pimpl_;
 // without namespaces i could do
 // class Impl* pimpl_; 
};

A::A()
{
 pimpl_->test();
}

}

Open in new window


I have tried this also but i get unresolved error
 
--file1--
namespace space_a {
namespace implementation {

class Impl
{
 public:
 Impl();
 void test();
};

}}


--file2--
#include file1

namespace space_a {

// new
namespace implementation {
  class Impl;
}

class A
{
 public:
 A(); 
 private:
 //new
 implementation::Impl* pimpl_;
};

A::A()
{
 pimpl_->test();
}

}

Open in new window


All is ok if class A is not in namespace
0
Comment
Question by:lavitz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 33606103
You've not provided any implementation for the pimp test function.
0
 

Author Comment

by:lavitz
ID: 33606134
I do. Its example. In my project there is implementation.
0
 
LVL 40

Accepted Solution

by:
evilrix earned 2000 total points
ID: 33606165
>> Its example. In my project there is implementation.
Well, that is the only thing wrong with your example, fix that and it builds fine.

//--file1--
namespace space_a {
namespace implementation {

class Impl
{
 public:
 Impl();
 void test(){}
};

}}


//--file2--
//#include file1

namespace space_a {

// new
namespace implementation {
  class Impl;
}

class A
{
 public:
 A(); 
 private:
 //new
 implementation::Impl* pimpl_;
};

A::A()
{
 pimpl_->test();
}

}

int main()
{
	space_a::A a;
}

Open in new window

0
 

Author Comment

by:lavitz
ID: 33606191
Hmm i see. So i have typo in my code.

I ask one additional question.
It is good?  to name class impl and class using that impl same name? and differ them by namespace?
So i could have:


namespace pipe_service {
namespace implementation {

class PipeService { // pimpl class

}

}}

and 

namespace pipe_service {

class PipeService { // class that use pimpl

}

}

Open in new window

0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 2000 total points
ID: 33606226
>> It is good?  to name class impl and class using that impl same name? and differ them by namespace?
I would probably not do that since it could cause you issues with ADL and make the implementation more convoluted than it needs to be.
http://en.wikipedia.org/wiki/Argument-dependent_name_lookup

I would stick to putting them in the same namespace and call them PipeService and PipeServiceImpl
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question