C++ group of struct

Hello All,

I have a C# code using "Interface" for including behavior from multiple sources in a struct. I need to convert the code to C++, is any similar to "Interface" in C++? or how can I get the same result in C++? THANKS.

main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        static void Main()
        {
            INTFC value;
            double[] DataValue = new double[6];

            value.T = new XYZ(1, 2, 3);
            value.R = new ABC(4, 5, 6);

            DataValue[0] = value.T.X;
            DataValue[1] = value.T.Y;
            DataValue[2] = value.T.Z;
            DataValue[3] = value.R.Qa;
            DataValue[4] = value.R.Qx;
            DataValue[5] = value.R.Qy;
            DataValue[6] = value.R.Qz;
        }



XYZ.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace XYZABC
{
    public struct XYZ
    {
        public double X;
        public double Y;
        public double Z;

        public XYZ(double x, double y, double z)
        {
            X = x;
            Y = y;
            Z = z;
        }
    }
}


ABC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace XYZABC
{
    public struct ABC
    {
        public double A;
        public double B;
        public double C;

        public ABC(double a, double b, double c)
        {
            A = a;
            B = b;
            C = c;
        }
    }
}


INTFC.cs
1
2
3
4
5
6
7
8
namespace XYZABC
{
    public interface INTFC
    {
        XYZ T { get; set;}
        ABC R { get; set;}
    }
}
What class implements the INTFC interface?
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "INTFC.h"
int main()
{
    INTFC* value; //value = new ...what?
    double[] DataValue = new double[6];

    value.T = new XYZ(1, 2, 3);
    value.R = new ABC(4, 5, 6);

    DataValue[0] = value.T.X;
    DataValue[1] = value.T.Y;
    DataValue[2] = value.T.Z;
    DataValue[3] = value.R.Qa;
    DataValue[4] = value.R.Qx;
    DataValue[5] = value.R.Qy;
    DataValue[6] = value.R.Qz;
}



XYZ.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace XYZABC
{
    struct XYZ
    {
        double X;
        double Y;
        double Z;

        XYZ(double x, double y, double z)
        {
            X = x;
            Y = y;
            Z = z;
        }
    }
}


ABC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace XYZABC
{
    struct ABC
    {
        double A;
        double B;
        double C;

        ABC(double a, double b, double c)
        {
            A = a;
            B = b;
            C = c;
        }
    }
}


INTFC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "XYZ.h"
#include "ABC.h"
namespace XYZABC
{
    class INTFC
    {
        XYZ getT() = 0;
        void setT(XYZ t) = 0;

        ABC getR() = 0;
        void setR(ABC r) = 0;
    }
}


EDIT: You may also want to consider include guards for your .h files.
http://en.wikipedia.org/wiki/Include_guard
Last edited on
Topic archived. No new replies allowed.