'CommonAPI C++ Service Build abstract class error
I am trying to build the CommonAPI C++ with D-BUS Hello World example. When I get to step 5 (https://github.com/GENIVI/capicxx-dbus-tools/wiki/CommonAPI-C---D-Bus-in-10-minutes#step5) and try and build the HelloWorldService.cpp I get the following error:
error: invalid new-expression of abstract class type ‘HelloWorldStubImpl’
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/dev/project/src/HelloWorldService.cpp:5:0:
/home/dev/project/src/HelloWorldStubImpl.hpp:7:7: note: because the following virtual functions are pure within ‘HelloWorldStubImpl’:
class HelloWorldStubImpl: public v1_0::commonapi::HelloWorldStubDefault {
How do I fix this?
HelloWorldService.cpp
// HelloWorldService.cpp
#include <iostream>
#include <thread>
#include <CommonAPI/CommonAPI.hpp>
#include "HelloWorldStubImpl.hpp"
using namespace std;
int main() {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
std::shared_ptr<HelloWorldStubImpl> myService =
std::make_shared<HelloWorldStubImpl>();
runtime->registerService("local", "test", myService);
std::cout << "Successfully Registered Service!" << std::endl;
while (true) {
std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(30));
}
return 0;
}
HelloWorldStubImpl.hpp
#ifndef HELLOWORLDSTUBIMPL_H_
#define HELLOWORLDSTUBIMPL_H_
#include <CommonAPI/CommonAPI.hpp>
#include <v1/commonapi/HelloWorldStubDefault.hpp>
class HelloWorldStubImpl: public v1_0::commonapi::HelloWorldStubDefault {
public:
HelloWorldStubImpl();
virtual ~HelloWorldStubImpl();
virtual void sayHello(const std::shared_ptr<CommonAPI::ClientId> _client,
std::string _name, sayHelloReply_t _return);
};
#endif /* HELLOWORLDSTUBIMPL_H_ */
HelloWorldStubImpl.cpp
#include "HelloWorldStubImpl.hpp"
HelloWorldStubImpl::HelloWorldStubImpl() { }
HelloWorldStubImpl::~HelloWorldStubImpl() { }
void HelloWorldStubImpl::sayHello(const std::shared_ptr<CommonAPI::ClientId> _client,
std::string _name, sayHelloReply_t _reply) {
std::stringstream messageStream;
messageStream << "Hello " << _name << "!";
std::cout << "sayHello('" << _name << "'): '" << messageStream.str() << "'\n";
_reply(messageStream.str());
};
Full error output
[ 40%] Built target HelloWorldClient
Scanning dependencies of target HelloWorldService
[ 50%] Building CXX object CMakeFiles/HelloWorldService.dir/src/HelloWorldService.cpp.o
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
from /usr/include/c++/7/bits/allocator.h:46,
from /usr/include/c++/7/string:41,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from /home/dev/project/src/HelloWorldService.cpp:2:
/usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = HelloWorldStubImpl; _Args = {}; _Tp = HelloWorldStubImpl]’:
/usr/include/c++/7/bits/alloc_traits.h:475:4: required from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = HelloWorldStubImpl; _Args = {}; _Tp = HelloWorldStubImpl; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<HelloWorldStubImpl>]’
/usr/include/c++/7/bits/shared_ptr_base.h:526:39: required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {}; _Tp = HelloWorldStubImpl; _Alloc = std::allocator<HelloWorldStubImpl>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’
/usr/include/c++/7/bits/shared_ptr_base.h:637:4: required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = HelloWorldStubImpl; _Alloc = std::allocator<HelloWorldStubImpl>; _Args = {}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’
/usr/include/c++/7/bits/shared_ptr_base.h:1295:35: required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<HelloWorldStubImpl>; _Args = {}; _Tp = HelloWorldStubImpl; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’
/usr/include/c++/7/bits/shared_ptr.h:344:64: required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<HelloWorldStubImpl>; _Args = {}; _Tp = HelloWorldStubImpl]’
/usr/include/c++/7/bits/shared_ptr.h:690:14: required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = HelloWorldStubImpl; _Alloc = std::allocator<HelloWorldStubImpl>; _Args = {}]’
/usr/include/c++/7/bits/shared_ptr.h:706:39: required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = HelloWorldStubImpl; _Args = {}]’
/home/dev/project/src/HelloWorldService.cpp:12:43: required from here
/usr/include/c++/7/ext/new_allocator.h:136:4: error: invalid new-expression of abstract class type ‘HelloWorldStubImpl’
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/dev/project/src/HelloWorldService.cpp:5:0:
/home/dev/project/src/HelloWorldStubImpl.hpp:7:7: note: because the following virtual functions are pure within ‘HelloWorldStubImpl’:
class HelloWorldStubImpl: public v1_0::commonapi::HelloWorldStubDefault {
^~~~~~~~~~~~~~~~~~
In file included from /home/dev/project/src-gen/v1/commonapi/HelloWorldStub.hpp:28:0,
from /home/dev/project/src-gen/v1/commonapi/HelloWorldStubDefault.hpp:16,
from /home/dev/project/src/HelloWorldStubImpl.hpp:5,
from /home/dev/project/src/HelloWorldService.cpp:5:
/home/dev/Git/capicxx-core-runtime/include/CommonAPI/Stub.hpp:34:18: note: virtual bool CommonAPI::StubBase::hasElement(uint32_t) const
virtual bool hasElement(const uint32_t _id) const = 0;
^~~~~~~~~~
/home/dev/Git/capicxx-core-runtime/include/CommonAPI/Stub.hpp:34:18: note: virtual bool CommonAPI::StubBase::hasElement(uint32_t) const
CMakeFiles/HelloWorldService.dir/build.make:62: recipe for target 'CMakeFiles/HelloWorldService.dir/src/HelloWorldService.cpp.o' failed
make[2]: *** [CMakeFiles/HelloWorldService.dir/src/HelloWorldService.cpp.o] Error 1
CMakeFiles/Makefile2:109: recipe for target 'CMakeFiles/HelloWorldService.dir/all' failed
make[1]: *** [CMakeFiles/HelloWorldService.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
