-1

I got some h file I need to implement but encountered a blocker. I have a class

Class A 
{
   B** something;
public:
   const B** getSomething() const;
}

any try to implement it falls with error is there a way to implement it as is? if not, what is the right way to get this member? explanation will be great!

when trying:

const B** A::getSomething() const 
{  
   return something; 
} 

error: "cannot covert lvalue of type 'B** const' to return type B const**

Matan
  • 83
  • 1
  • 5
  • Providing actual errors will help people find you a solution – donkopotamus Oct 11 '15 at 21:56
  • What is the actual error? What are you trying to implement? – Remy Lebeau Oct 11 '15 at 21:56
  • Any try? Like, what try? One problem might be your pointer isn't const enough, although I'm unsure how the scoping for const works at the moment. Give us the code to your try and your error and we can help you figure out what's wrong. – Cubic Oct 11 '15 at 21:56

1 Answers1

1

Because A::something is not a const. You can declare it as const:

const B** something;

Or declare return type of getSomething to be non-const:

B** A::getSomething() const 
{  
   return something; 
} 

Or better declare it as a reference:

B**& A::getSomething() const 
{  
   return something; 
}
SwiftMango
  • 15,092
  • 13
  • 71
  • 136