История изменений
Исправление wolverin, (текущая версия) :
) это объявление в бусте, я только попытался повторить похожее на ptree_fwd.hpp
можно и нужно форвард-декларировать сам class CJSON вместо инклуда
ну т.е. в хедере пишу только class CJSON;
, а в реализации уже все описываю?
типа такого
hpp
class CJSON;
cpp
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "DownloaderJSON.hpp"
class CJSON
{
private:
boost::property_tree::ptree pt;
public:
CJSON(const char * msg, const int lmsg)
{
std::stringstream ss;
ss.write(msg, lmsg);
boost::property_tree::read_json(ss, pt);
}
};
пробую такой вариант использовать и получаю ошибку
In file included from /usr/include/c++/8/memory:80,
from /usr/include/c++/8/thread:39,
from Downloader.cpp:5:
/usr/include/c++/8/bits/unique_ptr.h: In instantiation of ‘typename std::_MakeUniq<_Tp>::__single_object std::make_unique(_Args&& ...) [with _Tp = CJSON; _Args = {char*&, const int&}; typename std::_MakeUniq<_Tp>::__single_object = std::unique_ptr<CJSON, std::default_delete<CJSON> >]’:
Downloader.cpp:149:49: required from here
/usr/include/c++/8/bits/unique_ptr.h:831:30: error: invalid use of incomplete type ‘class CJSON’
{ return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from Downloader.cpp:21:
DownloaderJSON.hpp:3:7: note: forward declaration of ‘class CJSON’
class CJSON;
^~~~~
In file included from /usr/include/c++/8/memory:80,
from /usr/include/c++/8/thread:39,
from Downloader.cpp:5:
/usr/include/c++/8/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = CJSON]’:
/usr/include/c++/8/bits/unique_ptr.h:274:17: required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = CJSON; _Dp = std::default_delete<CJSON>]’
Downloader.cpp:149:49: required from here
/usr/include/c++/8/bits/unique_ptr.h:79:16: error: invalid application of ‘sizeof’ to incomplete type ‘CJSON’
static_assert(sizeof(_Tp)>0,
или такую в зависимости от того как указатель инициализировать
Downloader.cpp:150:36: error: invalid use of incomplete type ‘class CJSON’
auto pjson = new CJSON(msg, msgLen);
^
In file included from Downloader.cpp:21:
DownloaderJSON.hpp:3:7: note: forward declaration of ‘class CJSON’
class CJSON;
Исходная версия wolverin, :
) это объявление в бусте, я только попытался повторить похожее на ptree_fwd.hpp
можно и нужно форвард-декларировать сам class CJSON вместо инклуда
ну т.е. в хедере пишу только class CJSON;
, а в реализации уже все описываю?
типа такого
hpp
class CJSON;
cpp
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "DownloaderJSON.hpp"
class CJSON
{
private:
boost::property_tree::ptree pt;
public:
CJSON(const char * msg, const int lmsg)
{
std::stringstream ss;
ss.write(msg, lmsg);
boost::property_tree::read_json(ss, pt);
}
};
пробую такой вариант и получаю ошибку
In file included from /usr/include/c++/8/memory:80,
from /usr/include/c++/8/thread:39,
from Downloader.cpp:5:
/usr/include/c++/8/bits/unique_ptr.h: In instantiation of ‘typename std::_MakeUniq<_Tp>::__single_object std::make_unique(_Args&& ...) [with _Tp = CJSON; _Args = {char*&, const int&}; typename std::_MakeUniq<_Tp>::__single_object = std::unique_ptr<CJSON, std::default_delete<CJSON> >]’:
Downloader.cpp:149:49: required from here
/usr/include/c++/8/bits/unique_ptr.h:831:30: error: invalid use of incomplete type ‘class CJSON’
{ return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from Downloader.cpp:21:
DownloaderJSON.hpp:3:7: note: forward declaration of ‘class CJSON’
class CJSON;
^~~~~
In file included from /usr/include/c++/8/memory:80,
from /usr/include/c++/8/thread:39,
from Downloader.cpp:5:
/usr/include/c++/8/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = CJSON]’:
/usr/include/c++/8/bits/unique_ptr.h:274:17: required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = CJSON; _Dp = std::default_delete<CJSON>]’
Downloader.cpp:149:49: required from here
/usr/include/c++/8/bits/unique_ptr.h:79:16: error: invalid application of ‘sizeof’ to incomplete type ‘CJSON’
static_assert(sizeof(_Tp)>0,
или такую в зависимости от того как указатель инициализировать
Downloader.cpp:150:36: error: invalid use of incomplete type ‘class CJSON’
auto pjson = new CJSON(msg, msgLen);
^
In file included from Downloader.cpp:21:
DownloaderJSON.hpp:3:7: note: forward declaration of ‘class CJSON’
class CJSON;