Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*
766 Discussions

DPC++ Compile failed on std::make_shared when apply to class with virtual function

shenuo
Employee
1,627 Views
#include <CL/sycl.hpp>
#include <iostream>
#include <memory>
 
class A {
public:
int v = 0;
virtual void func() {};
};
 
 
class B : public A {
public:
virtual void func() override {
std::cout << 1 << std::endl;
std::cout << this << std::endl;
std::cout << reinterpret_cast<unsigned int>(this) << std::endl;
}
};
 
class C : public A {
public:
virtual void func() override {
std::cout << 2 << std::endl;
std::cout << this << std::endl;
std::cout << reinterpret_cast<unsigned int>(this) << std::endl;
}
};
 
int main()
{
//auto ptr = std::make_shared<B>();
 
std::shared_ptr<A> ptr = std::make_shared<B>();
std::shared_ptr<A> ptr2 = std::make_shared<C>();
 
 
/*auto ptr = std::make_shared<B>();
auto ptr2 = std::make_shared<C>();*/
std::cout << reinterpret_cast<unsigned int>(ptr.get()) << std::endl;
ptr->func();
 
std::cout << reinterpret_cast<unsigned int>(ptr2.get()) << std::endl;
ptr2->func();
 
return 0;
}
 
code above can be compiled by using other c++ compiler,
 I use DPC++ 2023 +vs2022
however DPC++2022 +vs2019 is ok
0 Kudos
3 Replies
shenuo
Employee
1,625 Views

I'm sorry .

code above CAN  NOT be compiled by using other c++ compiler, return error: error: 14;
 I use DPC++ 2023 +vs2022
however, DPC++2022 +vs2019 is ok
0 Kudos
VaishnaviV_Intel
Employee
1,540 Views

Hi,

 

Thanks for posting in Intel Communities.

Based on our internal discussion about creating a priority ticket if needed, I am going ahead and closing this case for now.

Please feel free to contact us further if you need any assistance from our side. 


Thanks & Regards,

Vankudothu Vaishnavi.


0 Kudos
shenuo
Employee
1,507 Views

I’m sorry, seems you didn't solve this problem ,why close it?

0 Kudos
Reply