NovusMobile
NovusMobile

Reputation: 1833

print pointer address of reference class

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);   

Upvotes: 0

Views: 123

Answers (2)

Panch
Panch

Reputation: 1187

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);

Upvotes: 1

Nishant Bijani A
Nishant Bijani A

Reputation: 148

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..

Upvotes: 1

Related Questions