J
josh
Hi, is there the possibility to create anonymous class (not object) in
C++ like do Java?
as an example:
in Java if I do:
// here Shape is an Interface that is like a c++ class wih only pure
virtual functions
public static void doShape(Shape s)
{
double v, a;
v = s.volume();
a = s.area();
System.out.println("Volume: " + v + " Area: "+ a);
}
than,
doShape(
new Shape() //
{
public double area() {return 0.0;}
public double volume() {return 0.0;}
}
);
the Java compiler creates a new anonymous class that implements the
Shape interface and
than returns its reference. So the above code is like I was doing:
class Implement implements Shape
{
public double area() {return 1.0;}
public double volume() {return 1.0;}
}
Implement i = new Implement();
doShape(i);
Thanks
C++ like do Java?
as an example:
in Java if I do:
// here Shape is an Interface that is like a c++ class wih only pure
virtual functions
public static void doShape(Shape s)
{
double v, a;
v = s.volume();
a = s.area();
System.out.println("Volume: " + v + " Area: "+ a);
}
than,
doShape(
new Shape() //
{
public double area() {return 0.0;}
public double volume() {return 0.0;}
}
);
the Java compiler creates a new anonymous class that implements the
Shape interface and
than returns its reference. So the above code is like I was doing:
class Implement implements Shape
{
public double area() {return 1.0;}
public double volume() {return 1.0;}
}
Implement i = new Implement();
doShape(i);
Thanks