c++ - How to fix the compile error using dynamic_cast in Android? -


  1. i working on mtk platform andoird 4.4 kk.

  2. build environment check result report

[os]: ubuntu 10.04.4 (64-bit) [ok]

[physical memory size] : 8079280 k-bytes [ok]

[make]: 3.81 (64-bit) [ok]

[perl]: 5.10.1 (64-bit) [ok]

[python]: 2.6.5 (64-bit) [ok]

[arm-linux-androideabi-gcc]: 4.7 (64-bit) [ok]

[gcc]: 4.4.3 (64-bit) [ok]

[jdk]: 1.6.0_33 (64-bit) [ok]

[bison]: 2.4.1 (64-bit) [ok]

[flex]: 2.5.35 (64-bit) [ok]

[gperf]: 3.0.3 (64-bit) [ok]

[mingw]: installed [ok]

[unix2dos/tofrodos]: installed [ok]

  1. code

(1) recordclient.bufops.cpp:

... recbufmanager mpimgbufmgr; mpimgbufmgr.init(); ...  // here want sp<icameraimgbuf> pimgbuf = mpimgbufmgr->getbuf(1); sp<recimgbuf> precimgbuf = dynamic_cast<sp<recimgbuf> >(pimgbuf); 

(2)

class recimgbuf : public icameraimgbuf {  public:     virtual                         ~recimgbuf(); } 

(3)

class recbufmanager : public refbase { public:     sp<icameraimgbuf>const&         getbuf(size_t index) const  { return mvimgbuf[index]; }  private:     vector< sp<icameraimgbuf> >     mvimgbuf; } 

(4)

bool recbufmanager:: init(){ ... recimgbuf* precimgbuf = recimgbuf::alloc(...); mvimgbuf.push_back(precimgbuf); ... } 

(5)

class icameraimgbuf : public iimgbuf, public icamerabuf { }; 

then got error: mediatek/platform/mt6592/hardware/mtkcam/v1/hal/client/camclient/record/recordclient.bufops.cpp: in member function 'bool android::nscamclient::nsrecordclient::recordclient::handlereturnbuffers(const android::vector&)': mediatek/platform/mt6592/hardware/mtkcam/v1/hal/client/camclient/record/recordclient.bufops.cpp:325:68: error: cannot dynamic_cast 'pimgbuf' (of type 'class android::sp') type 'class android::sp' (target not pointer or reference)

when delete following code:

sp<recimgbuf> precimgbuf = dynamic_cast<sp<recimgbuf> >(pimgbuf); 

it works fine.

how fix error ? thanks.

update:

  1. i thought android's sp equal pointer. changed code :

    sp<recimgbuf>& precimgbuf = dynamic_cast<sp<recimgbuf>& >(pimgbuf); 

the new error :

error: cannot dynamic_cast 'pimgbuf' (of type 'class android::sp') type 'class android::sp&' (source type not polymorphic)

even through add virtual method source type icameraimgbuf, this:

class icameraimgbuf : public iimgbuf, public icamerabuf { public:     virtual                         ~icameraimgbuf(){} }; 

dynamic_cast works on pointers or references


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -