rokoder

Tag: cpp

C++ Templates, not so generic

by on Mar.19, 2012, under Programming

Lets start with basic ideology of .h and .cpp files. When building libraries, the idea is to share only your header files and not your implementation (mean .cpp files). This is also the basics OOP’s encapsulation, abstraction etc, to hide the implementation details.

Now templates in C++ violates this encapsulation principle, bcoz C++ is a compiled language. And compiler generates all the needed (generic) code during compilation (it is different from Java as in Java this code can be generated in Java Run Time during execution and not at compilation. As Java compiled .class files contains enough info to generate a specific implementation later). Now to adhere to OOP we end up with fragile templates which are not 100% generic in nature.

Now there are two ways to implement templates.
(continue reading…)

Leave a Comment :, , , , more...

Java to C++

by on Dec.29, 2011, under Programming

Many times people from Java endup writing C++ code and vice versa (for vice versa check notes below). This is the beauty of working in such a dynamic/vast programming eco-system. This blog is to help them create an analogy between the two.

Below we have a sample Java code which we like to convert to C++.

interface MyInterface {
  void func1();
  int func2(int x, int y);
}

interface MyAnotherInterface {
  void func3();
  int func4(int x, int y);
}

abstract class MyAbstract implements MyInterface {
  void func1() {
    System.out.print("In func1");
  }
}

class MyConcreteClass extends MyAbstract
  implements MyAnotherInterface {
  int func2(int x, int y) {
    System.out.print("func2 x=" + x + ",y=" + y);
  }

  void func3() {
    System.out.print("in func3");
  }

  int func4(int x, int y) {
    System.out.print("func4  x=" + x + ",y=" + y);
  }
}

(continue reading…)

Leave a Comment :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

Archives

All entries, chronologically...