edisona / rcf-cpp

Automatically exported from code.google.com/p/rcf-cpp
1 stars 0 forks source link

error C2668: 'SF::serialize' : ambiguous call to overloaded function #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,Jarl. I have a template instantiation problem, please help me, 3KS.

What steps will reproduce the problem?
1.I have a user defined struct
struct ReportParameter
{
    BOOL    bNormal;
    BOOL    bOverflow;

    BOOL    bUsePort;

    BOOL    bSTM1;
    BOOL    bSTM4;
    BOOL    bSTM16;
    BOOL    bSTM64;

    vector<UINT>        arrayObjectID;
};

struct PeriodicalReport
{
    UINT    nReportNumber;  
    UINT    nReportType;
    UINT    nPeriod;
    UINT    nCreateOn;  
    UINT    nReportStatus;
    UINT    nPeriodicalFlag
    ReportParameter stParameter;
    string  strReportName;
    string  strCreateAt;
    string  strMinTime;
    string  strMaxTime;
};
2.Then I define a outside serialize function
namespace SF {

    inline void serializeBytes(SF::Archive &ar, const void *pbytes, 
const unsigned int cbSize)
    {
        if (ar.isRead())
            dynamic_cast<SF::IStream *>(ar.getIstream())->read
((char *)pbytes, cbSize);
        else if (ar.isWrite())
            dynamic_cast<SF::OStream *>(ar.getOstream())->writeRaw((char *)
pbytes, cbSize);
    }

    template<typename Archive>
        void serialize(Archive &ar,PeriodicalReport& 
periodicalReport)
    {
        serializeBytes(ar, &periodicalReport, offsetof
(PeriodicalReport, stParameter));

        ar  &periodicalReport.stParameter 
            &periodicalReport.strCreateAt 
&periodicalReport.strReportName &periodicalReport.strMinTime 
            &periodicalReport.strMaxTime 
&periodicalReport.nPeriodicalFlag ;
    }

3. And I also have a export dll function
void RCFSERIALIZEAPI SerializePeriodicalReport(PeriodicalReport& 
stPeriodicalReport, string& strBinaryData, UINT& nSize, BOOL bStore)
{
   SerializeObject(stPeriodicalReport, strBinaryData, nSize, bStore);
}

template <class Object>
void SerializeObject(Object& stObject, string& strBinaryData, UINT& nSize, 
BOOL bStore)
{
    if(bStore)
    {
        std::ostringstream os;
        SF::OBinaryStream ostr(os);
        ostr << stObject;
        strBinaryData = os.str();
        nSize = strBinaryData.length();
    }
    else
    {
        std::istringstream is(strBinaryData);
        SF::IBinaryStream istr(is);
        istr >> stObject;
    }
}

At Last, I build my project, get following errors:

d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(334) : error 
C2668: 'SF::serialize' : ambiguous call to overloaded function
1>        d:\d(work)\iamsvc9\src\server\include\rcfserializesplitsec.h
(248): could be 'void SF::serialize<SF::Archive>(Archive 
&,PeriodicalReport &)'
1>        with
1>        [
1>            Archive=SF::Archive
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(320): 
or       'void SF::serialize<T>(SF::Archive &,T &)'
1>        with
1>        [
1>            T=U
1>        ]
1>        while trying to match the argument list '(SF::Archive, U)'
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(345) : see 
reference to function template instantiation 'void SF::serialize_vc6<U>
(SF::Archive &,T &,const unsigned int)' being compiled
1>        with
1>        [
1>            T=U
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(425) : see 
reference to function template instantiation 'void SF::preserialize<T>
(SF::Archive &,T *&,const unsigned int)' being compiled
1>        with
1>        [
1>            T=T
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(424) : 
while compiling class template member function 'void 
SF::Serializer<T>::serializeContents(SF::Archive &)'
1>        with
1>        [
1>            T=T
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(175) : see 
reference to class template instantiation 'SF::Serializer<T>' being 
compiled
1>        with
1>        [
1>            T=T
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(200) : see 
reference to function template instantiation 'void 
SF::invokeCustomSerializer<T>(T **,SF::Archive &,int)' being compiled
1>        with
1>        [
1>            T=T
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(222) : see 
reference to function template instantiation 'void 
SF::invokeSerializer<U,T>(U *,T *,boost::mpl::int_<N> *,const U 
&,SF::Archive &)' being compiled
1>        with
1>        [
1>            U=const PeriodicalReport *,
1>            T=T,
1>            N=1
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(232) : see 
reference to function template instantiation 'void SF::invokeSerializer<U>
(U,SF::Archive &)' being compiled
1>        with
1>        [
1>            U=const PeriodicalReport *
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\serializer.hpp(353) : see 
reference to function template instantiation 'void 
SF::invokePtrSerializer<const T*>(U,SF::Archive &)' being compiled
1>        with
1>        [
1>            T=PeriodicalReport,
1>            U=const PeriodicalReport *
1>        ]
1>        d:\d(work)\iamsvc9\src\rcf\include\sf\stream.hpp(358) : see 
reference to function template instantiation 'SF::Archive &SF::operator 
&<T>(SF::Archive &,const T &)' being compiled
1>        with
1>        [
1>            T=PeriodicalReport
1>        ]
1>        d:\d(work)\iamsvc9\src\server\rcfserializedll\rcfserializedll.cpp
(67) : see reference to function template 
instantiation 'SF::WithSemanticsWrite &SF::WithSemanticsWrite::operator 
<<<Object>(const T &)' being compiled
1>        with
1>        [
1>            Object=PeriodicalReport,
1>            T=PeriodicalReport
1>        ]
1>        d:\d(work)\iamsvc9\src\server\rcfserializedll\rcfserializedll.cpp
(121) : see reference to function template instantiation 'void 
SerializeObject<PeriodicalReport>(Object &,stlp_std::string &,UINT 
&,BOOL)' being compiled
1>        with
1>        [
1>            Object=PeriodicalReport
1>        ]

What is the expected output? What do you see instead?
The compiler doesn't konw which function should call.
in serializer.hpp
there is a function,

   template<typename T>
    inline void serialize(
        Archive &                           archive, 
        T &                                 t)
    {
        typedef typename boost::is_enum<T>::type type;
        serializeEnumOrNot(archive, t, (type *) NULL);
    }

and in my cpp, also have a function
template<typename Archive>
        void serialize(Archive &ar,PeriodicalReport& 
periodicalReport)
    {}

What version of the product are you using? On what operating system?
RCF1.2,vc9(sp1),Windows XP,boost1.42.0,stlport5.2.1

Please provide any additional information below.
I just upgrade RCF1.0 to RCF1.2, my code works fine with RCF1.0.

Original issue reported on code.google.com by lor...@126.com on 23 Feb 2010 at 8:45

GoogleCodeExporter commented 9 years ago
I know if I move the serialize() function to type PeriodicalReport(inside 
serialize 
function),it should works fine. But I will not do that, because all my 
serialize 
function are defined outside the used defined type.

Original comment by lor...@126.com on 23 Feb 2010 at 8:58

GoogleCodeExporter commented 9 years ago
You shouldn't template the serialize() functions on Archive. Instead of

template<typename Archive> void serialize(Archive &ar,PeriodicalReport& 
periodicalReport)
{...}

, you should have

void serialize(SF::Archive &ar, PeriodicalReport& 
periodicalReport)
{...}

Original comment by jarl.lin...@gmail.com on 23 Feb 2010 at 12:02

GoogleCodeExporter commented 9 years ago

Original comment by jarl.lin...@gmail.com on 6 Mar 2010 at 1:23