Avatar of lavitz
lavitz
Flag for Poland asked on

pimpl + namespaces

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
C++

Avatar of undefined
Last Comment
evilrix

8/22/2022 - Mon
evilrix

You've not provided any implementation for the pimp test function.
lavitz

ASKER
I do. Its example. In my project there is implementation.
ASKER CERTIFIED SOLUTION
evilrix

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lavitz

ASKER
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

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
evilrix

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.