Google Groups Home
Help | Sign in
Message from discussion Porting C++ Template to Java Generic
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Aadain  
View profile
 More options May 16, 7:25 pm
Newsgroups: comp.lang.java.programmer
From: Aadain <aad...@gmail.com>
Date: Fri, 16 May 2008 16:25:42 -0700 (PDT)
Local: Fri, May 16 2008 7:25 pm
Subject: Porting C++ Template to Java Generic
I've run into a road block with porting some C++ code that makes use
of templates to Java.  In it, there is a main class I'll call A that
is a template class:

// C++
template <class T> class A
public:
    virtual T Evaluate() const = 0;

};

Other classes extend this class:

// C++
template <class T> class B : public A<T> {
public:
    B(const T &v) { value = v; }
    T Evaluate() const { return value; }
private:
    T value;

};

Now all of this is easy to implement in Java using Generic
programing.  The issue I'm having is when I try to implement code like
this:

template <class T1, class T2> class C : public A<T2> {
public:
    C(A<T1> a, A<T2> b) { t1 = a; t2 = b; }
    T2 Evaluate() {
        return t1->Evaluate() * t2->Evaluate();
    }
private:
    A<T1> t1;
    A<T2> t2;

};

Java complains about about the * operator being undefined for
arguments T1, T2;  Since Java doesn't have operator overloading, I
can't really see how to implement the same functionality.  Has anyone
ever encountered this type of problem, or can anyone see a way around
this issue?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google