C++ Binary Scope Resolution Operator and Classes

Is there a way to use "block" class scope resolution in C++ so that I don't have to write the same boilerplate code for every function in my class' implementation file.

I find it extremely repetitive to write the same class name and binary scope resolution operator (Classname::) when defining a function outside of the header file in C++.

In Objective-C I only need to include functions within the @implementation/@end block.

Objective-C Example:

// Buttons.h
@interface Buttons : UIView {
    NSMutableArray *buttonArray;
}
- (int)getNumberButtons;

// Buttons.m
#import "Buttons.h"
@implementation 
- (int)getNumberButtons 
{
    return [buttonArray count];
}
@end // End implemenation

C++ Example

// Buttons.h
class Buttons {
public:
    int getNumberOfButtons() const;
protected:
    std::vector<Button> buttons;
};
// Buttons.cpp
#include "Buttons.h"
int Buttons::getNumberOfButtons() const {
    return buttons.size();
}

Answers


No, unless you would implement it all in the header in the class definition (which you usually shouldn't).

Technically you could hack it with macros, but everyone else looking at the code would hate you for it. You'll have to get used to "the C++ way" here.

Depending on what IDE you work with, there are usually tools (e.g. Visual Assist X for Visual Studio) that help you generate some of the boilerplate from a class definition.


Need Your Help

jQuery BlockUi Message after another

javascript jquery jquery-plugins blockui

I'm using jQuery BlockUI plugin, and i have been able to sucessfully show a single message in the page, however... let's say that I want to show 3 messages , one after another.

LWUIT: Which subset of html and css can the htmlcomponent read?

java java-me lwuit

I noticed it can't read/parse everything you throw at it. It reads normal html, because i can see that, but i can't see the css that i use to make it look nice. although in the docs they say that c...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.