Moving class declaration from .cpp file to .h file

Discussion in 'C++' started by yinglcs@gmail.com, Jan 15, 2007.

  1. Guest

    I find the following class declaration in a .cpp file.
    If I need to move it to .h file so that other class can include that .h
    file and see this class,
    do I need to move all the implementation of all the code back to .cpp?
    Things like 'Constructor', 'Destructor', inline method, non-inline
    method?

    Thank you.

    class nsCanvasPattern : public nsIDOMCanvasPattern
    {
    public:


    nsCanvasPattern(cairo_pattern_t *cpat, PRUint8 *dataToFree)
    : mPattern(cpat), mData(dataToFree)
    { }

    ~nsCanvasPattern() {
    if (mPattern)
    cairo_pattern_destroy(mPattern);
    if (mData)
    nsMemory::Free(mData);
    }

    void Apply(cairo_t *cairo) {
    cairo_set_source(cairo, mPattern);
    }

    inline void Clear() {
    mPattern->clear();
    }

    protected:
    cairo_pattern_t *mPattern;
    PRUint8 *mData;
    };
     
    , Jan 15, 2007
    #1
    1. Advertising

  2. Wang Dong Guest

    Just move it, nothing will go wrong but any inlilne func must keep in .h if
    want it inline still.

    <>
    ??????:...
    >I find the following class declaration in a .cpp file.
    > If I need to move it to .h file so that other class can include that .h
    > file and see this class,
    > do I need to move all the implementation of all the code back to .cpp?
    > Things like 'Constructor', 'Destructor', inline method, non-inline
    > method?
    >
    > Thank you.
    >
    > class nsCanvasPattern : public nsIDOMCanvasPattern
    > {
    > public:
    >
    >
    > nsCanvasPattern(cairo_pattern_t *cpat, PRUint8 *dataToFree)
    > : mPattern(cpat), mData(dataToFree)
    > { }
    >
    > ~nsCanvasPattern() {
    > if (mPattern)
    > cairo_pattern_destroy(mPattern);
    > if (mData)
    > nsMemory::Free(mData);
    > }
    >
    > void Apply(cairo_t *cairo) {
    > cairo_set_source(cairo, mPattern);
    > }
    >
    > inline void Clear() {
    > mPattern->clear();
    > }
    >
    > protected:
    > cairo_pattern_t *mPattern;
    > PRUint8 *mData;
    > };
    >
     
    Wang Dong, Jan 16, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DrUg13
    Replies:
    1
    Views:
    490
    DrUg13
    Feb 10, 2004
  2. Alex Vinokur
    Replies:
    7
    Views:
    420
    Greg Comeau
    Nov 15, 2004
  3. Vinu
    Replies:
    9
    Views:
    661
  4. www.hitechskill.com
    Replies:
    0
    Views:
    1,378
    www.hitechskill.com
    Apr 9, 2006
  5. Belebele
    Replies:
    4
    Views:
    594
    Gavin Deane
    Oct 17, 2006
Loading...

Share This Page