can't call function

Hi everyone, Let me ask you questions. I wanna call function from another program to my program. I had put header file of another program in my program. But i still can't call. The program is like

LinuxCamera.h

class LinuxCamera
{
private:
LinuxCamera();
}

I wanna call that LinuxCamera function to my program. And inside my program, I wrote like


#include "LinuxCamera.h"
int main()
{
LinuxCamera cam;
cam.LinuxCamera();
}

I declared one variable under same class. But I still got error like "LinuxCamerawas not declared". Why? Please kindly let me know.
The function you're trying to call is private, so you can't access it from the main function. The class only is able to access it. You have to set the function as public.
There are 3 problems here:

You get that error because you need a semicolon after the class definition, like so:
1
2
3
class LinuxCamera
{ // stuff goes here
};


LinuxCamera::LinuxCamera() is a constructor - it gets called automatically when a LinuxCamera object is created but cannot be called otherwise.

Also, nothing outside of the class (with a few exceptions) is allowed to access LinuxCamera's protected and private members, so a LinuxCamera object cannot be created. When a LinuxCamera object is created, LinuxCamera::LinuxCamera() is called automatically, but it is a private member function so it can't be called. This will also give a compiler error.

1
2
3
4
5
6
7
// LinuxCamera.h

class LinuxCamera
{
    public:
    LinuxCamera ();
};

will allow the object to be created. Also, remove the line cam.LinuxCamera() : it gets done automatically and will actually cause an error
@Bandar: the function is a constructor, you can't call it anyway
Thanks a lot for your answer. I will try to solve it first. :)
@theranga
Thanks for correcting me. Yes, it is a constructor not a function. I think I'm a little tired. lol
Topic archived. No new replies allowed.