FeatureC++ - HelloWorld example

Download source code: HelloWorld.zip

1. Create two folders Base and World in a root folder for you HelloWorld example.


2. Create a file Hello.h in folder Base with the following content:

//File Base/Hello.h
#include <stdio.h>
class Hello {
public:
	    int run() { 
	    printf("Hello");
	    return 0;
	}
};

int main() {
	//create instance of "test"
	Hello myHello;

	//run Hello::run as entry-point of the app
	return myHello.run();
}
This is the base applicatin which prints "Hello" in method Hello::run. The method main creates an instance of class Hello and calls run.


3. Create a file Hello.h in folder World with the following content:
//File World/Hello.h
refines class Hello {
public:
	int run() {
	    //invoke refined method
	    int res = super::run(); 
	    if (res!=0)
	        return res;

	    printf(" World!");
	    return 0;
	}
};

This refinement prints "World" after the refined method run (by invoking super::run()) was executed successfully.


4. Create a file HelloWorld.equation in the root folder with the following content:
	Base
	World


5. Run fc++, compile, and execute the binary.

5a. On Unix/Linux or Windows with CygWin run the following commands:
  > fc++ -gpp HelloWorld
  > make .output.HelloWorld/Hello
  > .output.HelloWorld/Hello
5b. On Windows using the MS compiler run the following commands:
  > fc++ HelloWorld 
  > cl .output.HelloWorld/Hello.cpp
  > Hello