Error Accessing the constructor

Hi all,

The ERROR says calling the private constructor of the class is private within the context. What does that mean? How to call the private constructor of the class?


1
2
3
4
5
6
7
8
9
 class hippo
   {
 public:
  hippo(int z)
  {
   //code  
   }
~hippo(){}



hippo is the class here which I am calling.

hippo x = hippo(y); //I am getting the error here

How to resolve the above error. Suggestions are appreciated.

Thank you.
Nothing wrong with it. You need to show your actual code. I think your code might actually be calling a copy constructor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

class hippo
{
public:
   hippo(int z)
   {
      std::cout << "Constructed with " << z << '\n';
   }
   ~hippo(){}
};

int main()
{
   int y = 10;
   hippo x = hippo(y);
}
Last edited on
Thank you so much for the reply @lastchance

Sorry, The actual code cannot be shared.
Shruth LS wrote:
Sorry, The actual code cannot be shared.


Can't you just share a minimalist example of it which still exhibits the same problematic behaviour?
Or even better, a complete test program that demonstrates the issue.
Thanks again @lastchance

The copy constructor suggestion had really worked for me. Now the code is rectified.
Topic archived. No new replies allowed.