I’ve developed a working framework for windows at school, which has all the classes and methods needed for a window to work. Here’s an example of part of few classes, I’m not gonna paste all the code here tho.
Widget.h (base class)
class Widget {
public:
Widget(...);
...
virtual std::string getLabel() const;
virtual void setLabel(const std::string label);
...
private:
std::string m_label;
Widget* m_parent;
Measure m_position; // struct: int x, int y
Measure m_size;
};
Button.h
class Button : public Widget {
public:
Button(...);
...
virtual void setTarget(Widget* target);
...
private:
Widget* m_target;
};
LineEdit.h
class LineEdit : public Widget {
public:
LineEdit(...);
...
virtual void setMaximumLenght(int lenght);
...
private:
int m_maximumLength;
};
And so on… These are all just header files, and I have implemented methods etc. inside the corresponding .cpp file.
My homework for this period is to implement them for Mac’s OS-X in Objective-C and Cocoa, so the headers work in both OS-X and Windows. I can do rest myself, but I would like to know how to use these header files in the OS-X, and therefore just rewrite the implementations into a .m file, instead of .cpp. Any ideas? I’m new to this stuff.
You can combine .cpp files and .m files in the same project, which means that if your implementation doesn’t have any Windows-specific code you can add it to the project and compile it. There is also the concept of Objective-C++. With it, you can write code in
.mmfiles using both C++ and Objective-C and make calls between them.On the other hand, if you really need to implement everything in Objective-C, you’ll need to rewrite the headers to define Objective-C classes (not C++ ones) as well as rewriting the implementation.