Upgrading to Coherence for C++ 12.1.2 and The "Ambiguous Compilation Error" in Types Derived From AbstractAggregator

This weekend, I started the migration of some old C++ applications built on top of Coherence for C++ 3.7.1 API to its newest and refreshed version, released a few days ago. Version 12.1.2 introduces a lot of cool changes and features in the Coherence product, not mentioning the improvements done in different areas like installation, WebLogic integration, TCMP, Exabus, REST and Coherence*Extend. If you got yourself interested about those changes and improvements, check out the documentation at the following link, and please join us for the live virtual launch event on July 31st. Registration here.

After a couple hours migrating my projects from the oldest version to the newest, I got surprised with the following compiler message when trying to build the code:

call of overloaded 'Float64Sum(const coherence::lang::TypedHandle<coherence::util::extractor::ReflectionExtractor &)' is ambiguous 

If you are experiencing the same compiler message... don't worry. There is a quick and clean solution for this. This compiler error happens because in the 12.1.2 version of Coherence for C++ API, an overloaded version of the create() factory method was introduced in the types derived from the coherence::util::aggregator::AbstractAggregator class.

Until 3.7.1 version, the only way to instantiate an AbstractAggregator object was passing an instance of an coherence::util::ValueExtractor to its factory method. Now you also have the option to pass an instance of an coherence::lang::String::View. This object should contain the name of the attribute that will be aggregated. Automatically and behind the scenes, the Coherence for C++ API will fabricate an coherence::util::ValueExtractor for you.

In my case, I've changed my code from this:

Float64Sum::Handle scoreAggregator = Float64Sum::create(ReflectionExtractor::create("getScore")); 

To this:

Float64Sum::Handle scoreAggregator = Float64Sum::create("getScore"); 

And my project was able to be completely compiled again, both using the GNU Linux G++ and MS Visual Studio for C++ compilers.

Hope this blog helps you eliminate some hours of code debugging :-)

Comments:

Nice post and thanks for explaining the problem and solution.

Posted by Dave on August 07, 2013 at 05:39 AM BRT #

I have a strange compilation error in compiling my application with coherence 12.

I can compile the following example main which have no problems with coherence 3.7.1:

#include <coherence/lang/MemberHandle.hpp>
#include <coherence/net/NamedCache.hpp>
#include <coherence/net/CacheFactory.hpp>
#include <coherence/lang/System.hpp>

using coherence::lang::MemberHandle;
using coherence::lang::System;
using coherence::net::NamedCache;
using coherence::net::CacheFactory;

int main()
{
MemberHandle<NamedCache>* foo = new MemberHandle<NamedCache>( System::common(), CacheFactory::getCache("RealTimeObjectCache@NoDomain") );
return 0;
}

Any Idea?

Posted by guest on January 31, 2014 at 09:23 AM BRST #

In 12.1.2, there were some encapsulations in the API which causes some compilations problem, more precisely in the way about we handle public references.

But if in this snippet code what you are trying to do is the retrieval of an distributed cache (eg. NamedCache) so there is a simpler way to do this:

NamedCache::Handle foo = CacheFactory::getCache("RealTimeObjectCache@NoDomain");

Hope that helps!

Sincerely,

Ricardo Ferreira

Posted by guest on January 31, 2014 at 10:35 AM BRST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Ricardo Ferreira is just a regular person that lives in Brazil and is passionate for technology, movies and his whole family. Currently is working at Oracle Corporation.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today