Thread: What is the best way to do this data structure?

  1. #1
    Shadow12345
    Guest

    What is the best way to do this data structure?

    Originally I had;
    struct Triangle {
    float a, b, c, d, e, f, g, h, i;
    }

    Now I am trying to implement something like:
    struct Triangle {

    struct Vertex1 {
    float X, Y, Z;
    };

    struct Vertex2 {
    float X, Y, Z;
    };

    struct Vertex3 {
    float X, Y, Z;
    };
    };

    I am kind of new to this type of programming (OBJECT ORIENTED), what do you think would be the best way for setting up the scenario? I chose to use struct because there are no methods in this, just data.

    I can think of a few other ways to do this, i.e using classes, or typedefine the vertex structure before putting it into the triangle struct, etc, etc.

    Umm, I get errors when I try to access the variables
    I am doing:
    Code:
    				TriangleVector[Index]->VertexA->X = XA;
    				TriangleVector[Index]->VertexA->Y = YA;
    				TriangleVector[Index]->VertexA->Z = ZA;
    And my errors are:
    --------------------Configuration: lesson1 - Win32 Debug--------------------
    Compiling...
    Lesson1.cpp
    C:\Documents and Settings\04thibaultc\Desktop\re writing code!\10 - 2 02\Lesson1.cpp(865) : error C2273: 'function-style cast' : illegal as right side of '->' operator
    C:\Documents and Settings\04thibaultc\Desktop\re writing code!\10 - 2 02\Lesson1.cpp(865) : error C2227: left of '->X' must point to class/struct/union
    C:\Documents and Settings\04thibaultc\Desktop\re writing code!\10 - 2 02\Lesson1.cpp(866) : error C2273: 'function-style cast' : illegal as right side of '->' operator
    C:\Documents and Settings\04thibaultc\Desktop\re writing code!\10 - 2 02\Lesson1.cpp(866) : error C2227: left of '->Y' must point to class/struct/union
    C:\Documents and Settings\04thibaultc\Desktop\re writing code!\10 - 2 02\Lesson1.cpp(867) : error C2273: 'function-style cast' : illegal as right side of '->' operator
    C:\Documents and Settings\04thibaultc\Desktop\re writing code!\10 - 2 02\Lesson1.cpp(867) : error C2227: left of '->Z' must point to class/struct/union
    Error executing cl.exe.

    lesson1.exe - 6 error(s), 0 warning(s)
    Last edited by Shadow12345; 10-10-2002 at 08:49 AM.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    3 ways.....

    Public Inheritance - no good as triangle is not a vertex

    Private Inheritance - no need to overload and vertex funcs...so no

    Layering - Triangle has 3 vertex's so that's your boy!!!

    Code:
    struct Triangle {
    VERTEXT V1,V2,V3;
    }
    And as each vertex has the same properties (just different values, use a single VERTEX data struct

    <edit>damn - beaten.....</edit>

  3. #3
    Shadow12345
    Guest
    Okay so I think that's pretty similar to what I was doing, right? Can either of you point out why I was getting those errors? They surprised me.

  4. #4
    Shadow12345
    Guest
    TriangleVector.push_back(new Triangle);

    Its a pointer...

    there must be another reason for that error because that's the only way i create vectors.

    well anyway I'm at home now not at school and it is working here and that's all I really care about.

    Okay I take that back this isn't working anymore, here is the code
    Code:
            while(fin.good()) {
                    TriangleVector.push_back(new Triangle);
                    
                    fin >> Dummy;
    
                    fin >> XA;
                    fin >> YA;
                    fin >> ZA;
    
                   
    			
    
                    fin >> Dummy;
                    fin >> Dummy;
    
                    fin >> XB;
                    fin >> YB;
                    fin >> ZB;               
               
                    fin >> Dummy;
                    fin >> Dummy;
    
                    fin >> XC;
                    fin >> YC;
                    fin >> ZC;
    
    				TriangleVector[Index]->VertexA->X = XA;
    				TriangleVector[Index]->VertexA->Y = YA;
    				TriangleVector[Index]->VertexA->Z = ZA;
    Here is what I am actually using for the triangle struct:
    Code:
    struct Vertex {
    	float X, Y, Z;
    };
    class Triangle{
    	struct VertexA {
    		float X, Y, Z;
    	};
    	struct VertexB {
    		float X, Y, Z;
    	};
    	struct VertexC {
    		float X, Y, Z;
    	};
    };
     vector<Triangle*>TriangleVector;
    You can say it, I'm an idiot, but say that after you fix my problem
    Last edited by Shadow12345; 10-10-2002 at 05:12 PM.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    TriangleVector[Index]->VertexA->X = XA;
    change to:

    TriangleVector[Index]->VertexA.X = XA;
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Include GTK+ just for a data structure?
    By Jesdisciple in forum C Programming
    Replies: 0
    Last Post: 04-12-2009, 07:19 PM
  2. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 12:42 PM
  3. Data structure implementation
    By fkheng in forum C Programming
    Replies: 3
    Last Post: 07-31-2003, 07:44 AM
  4. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 06:03 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM