Create a Structure Containing Functions : Structure Method « Structure « Visual C++ .NET






Create a Structure Containing Functions

 
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
struct Point {
private: int x;
public:
    void translate(int xx){x += xx;}
    void setX(int xx){x = xx;}
    int getX(){return x;}
};
int main(void) {
    Point point;
    point.setX(10);
    point.translate(10);
    Console::Write("x = ");
    Console::WriteLine(point.getX());
    return 0;
}

   
  








Related examples in the same category