Thread: Simulating Templates or Classes in C

  1. #1
    Registered User
    Join Date
    Apr 2007

    Unhappy Simulating Templates or Classes in C


    I am trying to convert a PR-Tree algorithm from C++ to C (if anyone knows of a ready-made C one I'll be very grateful). However, this algorithm has a lot of templates and classes, is there a way to convert them to C?

    The following is an example:

    #define box_t box_type<coord_t,dim>
    template<class coord_t, size_t dim>
    class box_type {
    	size_t id;  // used as bid of child when act as bounding boxes
    	coord_t lo_[dim];
    	coord_t hi_[dim];
    	// each box has a unique id, assigned by the application.
    	inline bool intersect(box_t& t) {
    		for (size_t i=0; i<dim; i++) {
    			if (t.lo_[i] > hi_[i] || t.hi_[i] < lo_[i]) return false;
    		return true;
    	inline bool contain(box_t& t) {
    		for (size_t i=0; i<dim; i++) {
    			if (t.lo_[i] < lo_[i] || t.hi_[i] > hi_[i]) return false;
    		return true;
    Thanks for helping.


  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Well, you could convert the algorithms present in those member functions into C. What have you tried?

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2005, 12:22 AM
  2. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  3. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  4. VC++6: exporting classes containing templates
    By ttt in forum Windows Programming
    Replies: 2
    Last Post: 09-15-2003, 11:38 AM