Click here to Skip to main content
15,867,453 members
Articles / Mobile Apps

An Introduction to Three VC++ Macros: How They Came To Be

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
7 Dec 2011CPOL2 min read 26.3K   3   3
An introduction to three VC++ Macros: How they came to be

I’ve been recently working on a C++ project and ran into a task where I had to move many inline header functions out of the header and into the corresponding .cpp file.

Visually, I wanted to convert:

Biscuit.h

C++
class Biscuit
{
public:
    virtual void Taste(int chompiness) { m_ChompRating = chompiness; }
private:
    int m_ChompRating;
}

into:

Biscuit.h

C++
class Biscuit
{
public:
    virtual void Taste(int chompiness);
private:
    int m_ChompRating;
}

Biscuit.cpp

C++
void Biscuit::Taste(int chompiness)
{
    m_ChompRating = tastiness;
}

We’ve all been there. It is usually an exercise in our copy and paste skills, and an opportunity to work on our RSI. I thought there must be a better way! So I scoured the Internet but no one seems to talk about it. It seems every programmer has just accepted that the only way to get this done is to stop mucking about on Google and push your fingers to the keys.

I was still not satisfied. I asked the collective brains of Stack Overflow and the only solution I got was to purchase Visual Assist. I’ve tried Visual Assist. It is a brilliant product. It is also a brilliantly expensive product. Nawaz, from Stack Overflow (he is the one that looks like a baby) challenged me to write a macro myself, and share it, because “it wouldn’t be too difficult to write”.

Hah! It was not that difficult to get something that worked some of the time. It was difficult to create something that worked all of the time. I knew nothing about macros, other than how to record them and see the generated code. Finally, after a bit of reverse engineering, a tiny bit of reading and some code stealing inspired coding, I have a set of macros I am quite happy with. Over my next 3 blog posts, I will share these macros with you, and on the way, we will build up a few good utilities:

  1. How to flip between the header and cpp file
  2. Automatically adding an implementation skeleton to the cpp file from the header definition
  3. Moving a function defined inline in the header into the cpp file

And hopefully, some Googler will be able to make use of these macros. See you soon.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Web Biscuit
United Kingdom United Kingdom
At Web Biscuit, you can find software, articles, a good dollop of quality and an unhealthy obsession over biscuits.
Website: http://www.webbiscuit.co.uk
Twitter Watch: http://twitter.com/WebBiscuitCoUk

Comments and Discussions

 
QuestionIt already exists. Pin
Pablo Aliskevicius13-Dec-11 3:23
Pablo Aliskevicius13-Dec-11 3:23 
Bugprivate fileds in C++ Pin
Alex Cohn7-Dec-11 2:51
Alex Cohn7-Dec-11 2:51 
GeneralRe: private fileds in C++ Pin
WebBiscuit7-Dec-11 6:16
WebBiscuit7-Dec-11 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.