Hey guys, I'm working on converting some existing Java Code over to C++, trying to use only built in standard libraries because the platform we are building on we won't be able to have any outside libraries, and it's been a while since I had to write "fancy" c++ code so here is probably an easy question for you.

I have a base class in Java that is a Number as a return type, each of its chidren return a different type (int, double, float etc). Also have a function that takes an object in java, and each child acts differently on it.

public abstract class Base{
 public abstract Number doSomething();
public abstract void setMe(Object blah);
public class Child1 extends Base{
public Number doSomething(){
value= new Double(somedouble);
return value;

public void setMe(Object blah){

What would be the best way to go about this? C++ doesn't have a generic like Number.. can I use a template in c++ aka template<class Number>.

Do I have to do anything special to make that work? Also this will be on a Linux system.

Edited by Izarian: added more detail

8 Years
Discussion Span
Last Post by Izarian

I am trying to stay away from Boost if possible, and use the built in typical standard libraries. Is there not a way to do it with templates and the like? It's been a while since I had to do any template wrangling, but I will head to boost as a last resort if I can just yank out the few headers that are needed and not have to install it onto the end system.


Oh I probably should mention, this code will get ported to Solaris 8, so trying to minimize anything that might not port well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.