User Profile

Collapse

Profile Sidebar

Collapse
CaptainBly
CaptainBly
Last Activity: Oct 11 '07, 07:45 PM
Joined: Oct 2 '07
Location: Illinois
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • CaptainBly
    replied to Overloading the [] operator question
    in C
    What I have tried and hasn't worked

    Code:
    class foo {
    private:
    float var[3];
    public:
    float operator[] (int a);
    void setx(int i) {var[0]=i;}
    void sety(int i) {var[1]=i;}
    void setz(int i) {var[2]=i;}
    }
    
    //and somewhere in the .cpp
    float Foo::operator[] (int a)
    {
    switch(a)
    {
    case 0:
    return var[0];
    break;
    case
    ...
    See more | Go to post

    Leave a comment:


  • CaptainBly
    started a topic Overloading the [] operator question
    in C

    Overloading the [] operator question

    Alright, say I have a class

    Code:
    class something {
    private:
    float q[3];
    
    public:
    float valx() {return q[0]}
    float valy() {return q[1]}
    float valz() {return q[2]}
    }
    and what I want instead of having to call valx() valy() valz() is an [] operator.

    Code:
    something a;
    x=a[0];
    y=a[1];
    z=a[2];
    ...
    See more | Go to post

  • CaptainBly
    replied to complex struct access question.
    in C
    My code eventually evolved to this.

    Code:
    //linklist.h
    
    class Node
    {
    
               private:
                       
                    void *d;
               Node* n;
               Node* p;                    
              
               public:
               void* obj() {return d;}
               Node* next() {return n;}
               Node* prev() {return p;}
    ...
    See more | Go to post

    Leave a comment:


  • CaptainBly
    replied to complex struct access question.
    in C
    Ok I started a separate program in order to help me more fully understand the way you organize your data. Let me know if I'm getting the gist of it or if you know a good reference I should look into (I.E. Linked Lists for the Dense).



    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    
           
           
    struct aNode {
    ...
    See more | Go to post

    Leave a comment:


  • CaptainBly
    replied to complex struct access question.
    in C
    Thank you for the great reply, though I'm still not sure I understand the flow of what you are doing.

    if I were to create a linked list of objects how would I access the member functions?

    as such?
    Code:
    LinkedList *objects = createobject();
    
    objects->current->vertex->x=1;
    
    objects->current->vertex->y=2;
    objects->current->vertex->z=3;
    ...
    See more | Go to post

    Leave a comment:


  • CaptainBly
    started a topic complex struct access question.
    in C

    complex struct access question.

    Okay I've been spending lots of time on this and it's giving me a migraine so I go humble and ask the guru's here.

    I have several structs

    Code:
    typedef struct vert
    {
    int x,y,z;
    struct vert * next;
    struct vert * prev;
    } vertex_type;
    
    typedef struct poly
    {
    int x,y,z;
    struct poly * next;
    struct poly * prev;
    } polygon_type;
    ...
    See more | Go to post
No activity results to display
Show More
Working...