Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualThe King2

Posted 01 April 2013 - 01:28 AM

If you want to implement sort of an auto increment type id (here called family):

 

#pragma once

struct BaseComponent
{
    typedef unsigned int Family;

protected:
    static Family family_count;
};

template <typename Derived>
struct Component : public BaseComponent {
    static Family family(void);
};

template<typename C>
unsigned int Component<C>::family(void) {
    static BaseComponent::Family Family = family_count++;
    return Family;
}

//"always" = if first called in that order
class Derived : public Component<Derived> {};
Derived::family(); // always 0
class Derived2 : public Component<Derived2> {};
Derived2::family(); //always 1 

#2The King2

Posted 01 April 2013 - 01:28 AM

If you want to implement sort of an auto increment type id (here called family):

 

#pragma once

struct BaseComponent
{
    typedef unsigned int Family;

protected:
    static Family family_count;
};

template <typename Derived>
struct Component : public BaseComponent {
    static Family family(void);
};

template<typename C>
unsigned int Component<C>::family(void) {
    static BaseComponent::Family Family = family_count++;
    return Family;
}

//"always" = if first called in that order
class Derived : public Component<Derived> {};
Derived::family(); // always 0
class Derived2 : public Component<Derived2> {};
Derived2::family(); //always 1 

 

 

 

 


 


#1The King2

Posted 01 April 2013 - 01:26 AM

If you want to implement sort of an auto increment type id (here called family):

 

#pragma once

struct BaseComponent
{
    typedef unsigned int Family;

protected:
    static Family family_count;
};

template <typename Derived>
struct Component : public BaseComponent {
    static Family family(void);
};

template<typename C>
unsigned int Component<C>::family(void) {
    static BaseComponent::Family Family = family_count++;
    return Family;
}

class Derived : public Component<Derived> {};
Derived::family(); // always 0
class Derived2 : public Component<Derived2> {};
Derived2::family(); //always 1

 

 

 

 


 


PARTNERS