Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

we need this ability !!!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
chloe - 02 Jul 2004 04:16 GMT
My English is poor, so there are many syntax error, i am sorry.
In the past time ,we write code that can be reuse.
But OOP  only let us reuse the framework and the design mode.
So, now, we write GP code with template, but today, we found GP also can not satisfy us.
For Instance, the boost library's bind had written as very long code, but the code is very similar.
pelese look at this code:

//**********************macro version

#define PRODUCE_CLASS(classname, member) \
    template<typename T> \
    class classname \
    { \
    protected: \
        T m_##member; \
    public: \
        classname() : m_##member(T()) { } \
        void set_##member(T& member) {  m_##member = member; } \
        T& get_##member() { return m_##member; } \
    };

//**********************GP version

template<typename T>
class Base
{
protected:
    T m_data;
public:
    classname() : m_data( T()) { }
    void set_data(T& data) {  m_data = member; }
    T& get_data() { return m_data; }
};

//*********************use macro version

PRODUCE_CLASS(Alpha, alpha);
PRODUCE_CLASS(Color, color);

struct A : public Alpha<float>, public Color<int>
{
    void func()
    {
        set_alpha(0.1f);
        set_color(0);
    }
};

extern A* p;
float a = p->get_alpha();
int c = p->get_color();

//this code is very definitude, but can not debug!

//*********************use GP version

template<typename T>
class Alpha : public Base<T> { };

template<typename T>
class Color : public Base<T> { };

template<class Dest, class Src>
inline Dest* get_ptr(Src* srcptr)
{
    return static_cast<Dest*>(srcptr);
}

struct A : public Alpha<float>, public Color<int>
{
    void func()
    {
        get_ptr< Alpha<float> >(this)->set_data(0.1f);
        get_ptr< Color<int> >(this)->set_data(0);
    }
};

extern A* p;
float a = get_ptr< Alpha<float> >(p)->get_data();
int c = get_ptr< Color<int> >(p)->get_data();

//this code is not definitude, but can debug!

//**********************************************************

Summarize , wo need debug the Macro code, and we think this is not too difficulty to Developers.
Stefan Slapeta - 02 Jul 2004 13:43 GMT
> Summarize , wo need debug the Macro code, and we think this is not too difficulty to Developers.

As macros are replaced during preprocessing, the (only) solution can be
to write the output of the preprocessor to a file. See commane line
option /P in the help.

Stefan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.