structure containing class; access problem.

im writing a programe to calculate the steering angle of a wheel given design specs. not to bore you all with trivial race car suspension geometry design, but knowing the non linear rack motion to wheel angle is important for determining maximum grip.

my actually problem is this: i have a class "data" which has a struct "steerAngleData" in it. i initialized the struct steerAngleData inner, in the IMP file, and can use to data::PrintList fine. however when i try to input values into the struct in another class, it will not recognize the structure. i have tried using derived classes, friends, and virtual

i've spent a good amount of time on google to no avale, so if this is a very obvious problem(which im sure it is) im sorry.

im completely out of ideas at this point, so any help would be great.
Thanks




HEADER###
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
//  ackerman.h
//  ackerman project
//
//  Created by Daniel Melvin on 5/6/12.


#ifndef ackerman_project_ackerman_h
#define ackerman_project_ackerman_h

 class data                  //data storage
{
public:
    data(); 
    struct steerAngleData     //structure in question
    {
        double rackTravel;
        double wheelAngleRaw;
        double wheelAngle;
    };
    
public:
    void printList();
    
    friend class getSpecs;
};

//code cut down for space:
    
class getSpecs: public steeringAngle, public trigCalc, public data      //class i would like to be able to access structure
{
protected:   
    double steerArmAngle;
    double steerRad;
    double centerToSteerAxis;
    double rackLocationY;
    double rackLocationX;
    double tieRodRad;
    double rackMotion;
    int rackInterval;
    double centerToCenterD;
    double tierodToIntersection;
    double intersectionHeight;
    double intersectionP2X;
    double intersectionP2Y;
    double intersectionP3X;
    double intersectionP3Y;
    
public:
    getSpecs();
    void GetSpecifications();
    void calcGeometry();
    void calcCenterToCenterD();
    void calcTierodToIntersection();
    void calcIntersectionHeight();
    void calcIntersectionMidPt();
    void calcIntersectionPt();
    void calcSteeringAngle();
    void printAngles();
};

#endif 


IMP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
//  ackermanImp.cpp
//  ackerman project
//
//  Created by Daniel Melvin on 5/6/12.


#include <iostream>
#include <math.h>
#include "ackerman.h"
using namespace std;

#ifndef ackermanImp
#define ackermanImp

data::data()
{
    int *abc=0;
    steerAngleData inner[21];
    for (int i=0; i<21; i++)
    {
        inner[i].rackTravel=0.0;
        inner[i].wheelAngleRaw=0.0;
        inner[i].wheelAngle=0.0;
    }
    steerAngleData outer[21];
    for (int i=0; i<21; i++)
    {
        outer[i].rackTravel=0.0;
        outer[i].wheelAngleRaw=0.0;
        outer[i].wheelAngle=0.0;
    }
    
}
void data::printList()
{
    steerAngleData left[21];
    for (int i=0; i<21; i++)
    {
        cout<<inner[i].rackTravel<<"\t"<< left[i].wheelAngleRaw<<"\t"<<left[i].wheelAngle;
    }
    steerAngleData right[21];
    for (int i=0; i<21; i++)
    {
        cout<<outer[i].rackTravel<<"\t"<< left[i].wheelAngleRaw<<"\t"<<left[i].wheelAngle;
    }

}
    

 steeringAngle::steeringAngle()
 
    {
        steerAngleRaw=0;
        steerAngleFinal=0;
    }
    

    getSpecs::getSpecs()
        :trigCalc(), 
        steeringAngle(),
        data()
    {
        steerArmAngle=0.0;
        steerRad=0.0;
        centerToSteerAxis=0.0;
        rackLocationY=0.0;
        rackLocationX=0.0;
        tieRodRad=0.0;
        rackMotion=0.0;
        rackInterval=0.0;
        centerToCenterD=0.0;
        tierodToIntersection=0.0;
        intersectionHeight =0.0;
        intersectionP2X=0.0;
        intersectionP2Y=0.0;
        intersectionP3X=0.0;
        intersectionP3Y=0.0;
        
    } 

    void getSpecs::GetSpecifications()
    {
    //code removed here
    }
    
    void getSpecs::calcGeometry() //struct access problem: i would like to input data from this class.
    {
         rackMotion=rackMotion/10;
        
        double temprackLocation=rackLocationY;              //inside movment;
        for (int i=0; i<10; i++)
        {        
            temprackLocation=temprackLocation-(rackMotion*i);
            
        getSpecs::calcCenterToCenterD();
        getSpecs::calcTierodToIntersection();
        getSpecs::calcIntersectionHeight();
        getSpecs::calcIntersectionMidPt();
        getSpecs::calcIntersectionPt();
        getSpecs::calcSteeringAngle();
        
        
        inner[i].wheelAngleRaw=steerAngleFinal; //error here- "use of undeclared identifier "inner"
        inner[i].wheelAngle=steerAngleFinal;
            
            
        }    
        
        temprackLocation=rackLocationY;                  //outside movment
        for (int i=0; i<10; i++)
        {        
            temprackLocation=temprackLocation+(rackMotion*i);
            
            getSpecs::calcCenterToCenterD();
            getSpecs::calcTierodToIntersection();
            getSpecs::calcIntersectionHeight();
            getSpecs::calcIntersectionMidPt();
            getSpecs::calcIntersectionPt();
            getSpecs::calcSteeringAngle();
            
            
            
     //       outer[i].wheelAngleRaw=steerAngleRaw;
     //       outer[i].wheelAngle=steerAngleFinal;
        }
            
            
        
//code removed here:


            
#endif




thanks for the help
Last edited on
Please point out where you are tryaing to acces this structure and get the error?

For example i see the following code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    void getSpecs::calcGeometry() //#######################################
    {
         rackMotion=rackMotion/10;
        
        double temprackLocation=rackLocationY;              //inside movment;
        for (int i=0; i<10; i++)
        {        
            temprackLocation=temprackLocation-(rackMotion*i);
            
        getSpecs::calcCenterToCenterD();
        getSpecs::calcTierodToIntersection();
        getSpecs::calcIntersectionHeight();
        getSpecs::calcIntersectionMidPt();
        getSpecs::calcIntersectionPt();
        getSpecs::calcSteeringAngle();
        
        
        inner[i].wheelAngleRaw=steerAngleFinal; //error here- "use of undeclared identifier "inner"
        inner[i].wheelAngle=steerAngleFinal;
            
            
        }  


And where inner is defined?

In your constructor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
data::data()
{
    int *abc=0;
    steerAngleData inner[21];
    for (int i=0; i<21; i++)
    {
        inner[i].rackTravel=0.0;
        inner[i].wheelAngleRaw=0.0;
        inner[i].wheelAngle=0.0;
    }
    steerAngleData outer[21];
    for (int i=0; i<21; i++)
    {
        outer[i].rackTravel=0.0;
        outer[i].wheelAngleRaw=0.0;
        outer[i].wheelAngle=0.0;
    }
    
}


inner and outer are local variables that will be destroyed after the exiting the constructor.
Last edited on
that makes sense, but why can i access variables in derived classes that were initialized in the parent class? if that works, why cant i get the structure to work, even if getSpecs is a derived class of data?

if i initialize the structure outside any class it would be a global struct, and accessible to all files, including main driver correct?


this is where i am trying to modify a struct value.

1
2
3
       
        inner[i].wheelAngleRaw=steerAngleFinal; //error here- "use of undeclared identifier "inner"
        inner[i].wheelAngle=steerAngleFinal;


thanks
This is a scope problem. Your 'inner' and 'outer' arrays do not exist. You declare them in your data() constructor, which means they go out of scope and die as soon as the constructor exits.

They are not part of your data class. If you want them to be part of your class, they have to actually be declared in the class body:

1
2
3
4
5
6
7
class data
{
//...
  steerAngleData inner[21];
  steerAngleData outer[21];
//...
};


Do this, and remove the declaration from the constructor, and you should be good to go.
disch, and vlad, you are my new best friends.

it works, thanks a ton guys.



Last edited on
Topic archived. No new replies allowed.