0

Code Summary:

Need to pass object of Camera From TestCamera.cpp to Test1.cpp. I created a object of class into TestCamera.cpp Now, I want to pass this to Test1, so I passed this to another object.

Anyhow I am getting error of "Camera*" into Test1.cpp .

I am new to CPP. Is it perfect way to pass another class & print it's pointer value?

TestCamera.cpp

Camera * cameraClient=static_cast<Camera *>();

    (Test1 *)->captureImage(*cameraClient*);

Test1.cpp

int Test1::captureImage(const Camera*  Cam) {

    jint lResult;
    jlong ad = (jlong)&Cam;
        LOGI("Test1: pointer : APP: %ld",ad);   
NovusMobile
  • 1,813
  • 2
  • 21
  • 48
  • 1
    You should show a bit more code, because those two lines you showed in `TestCamera.cpp` are so wild I can't even begin to figure out what you are trying to achieve. – paddy Mar 14 '16 at 05:22

2 Answers2

1

i am not getting your whole code, but just giving you hint that you are passing it wrong way..

you need to pass like this:

(Test1 *)->captureImage(cameraClient);

but, i doubt because you are not allocating memory to cameraClient.

below is extra advise, which is out of your question:

in C++, when you want to create an object of a class dynamically, then you need to allocate memory using new like below:

Camera * cameraClient= new Camera;  

which instantiate class of Camera & then pass it to CaptureImage if Test1 class already instantiated..

Nishant Bijani A
  • 148
  • 1
  • 13
  • for both I need to include Camera.h class. I am getting :previous definition of 'class: error. – NovusMobile Mar 14 '16 at 05:43
  • your question is just to print pointer value, i had given adequate answer to your question. if any other error, then post full code with another question – Nishant Bijani A Mar 14 '16 at 05:51
  • Should I write : int Test1::captureImage(const Camera* camera). Camera * in Test1 class or I need to use Camera only ? – NovusMobile Mar 14 '16 at 06:00
  • if you are passing pointer then you need like i wrote in my answer, then you need to keep Test1::captureImage(Camera* camera). – Nishant Bijani A Mar 14 '16 at 06:10
1

The code snippet in TestCamera.cpp is not right, when you say that you are creating an object then you need to either use new operator or define an object as below

Camera * cameraClientPtr=new Camera; // For default constructor
Camera cameraClientObj;

The way you invoke method captureImage also not right. If you have Test1 pointer created using any of the aforementioned way then you invoke the method as below,

Test1Ptr->captureImage(cameraClientPtr);

Test1Obj.captureImage(&cameraClientObj);
Panch
  • 1,097
  • 3
  • 12
  • 43
  • Should I write : int Test1::captureImage(const Camera* camera). Camera * in Test1 class or I need to use Camera only ? – NovusMobile Mar 14 '16 at 06:01
  • 1
    If you are passing as a pointer then use `int Test1::captureImage(const Camera* camera)`, for passing as a reference `int Test1::captureImage(const Camera& camera)`. You can go through this [link](http://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value) and this [link](http://courses.washington.edu/css342/zander/css332/passby.html) for more information on how to pass data to method. – Panch Mar 14 '16 at 06:50