declaring vectors issue

Pages: 12
I'm trying to put a series of classes into a vector but weirdly visual studio keeps saying my object could be declared as an int "which needs an identifier".

this is in the .cpp file of my class. Should I stick these in my header file or whatever? this is really weird.

Furthermore, it refuses to allow the qva_Font to be treated as a vector
1
2
3
4
5
6
7
8
9
10
.................

CLetter125 q125;
 
   CLetter126 q126;
 
 
vector <CLetter *> qva_Fonts;

qva_Fonts->push_back(q1);	 

Last edited on
CLetter125 q125;OK assuming that CLetter125 is a valid class

CLetter126 q126;same..

vector <CLetter *> qva_Fonts;OK if you wrote #include <vector> and using namespace std; or using std::vector; and CLetter is a valid class.

qva_Fonts->push_back(q1);Wrong. ->is used when you need a member/method of an object an you only have a pointer to it. Here you have a vector of pointers to objects, not a pointer to vector of objects.
Line qva_Fonts.push_back(q1); would be OK assuming that q1 is a pointer to a CLetter (or derived type) object.
Last edited on
I've done exactly what you have said yet its still not working. What even more confusing is that on vector <CLetter *> qva_Fonts; it thinks qva_Fonts is an int.

I've now put everything into the header file (globally) since they are just declarations. But it wants to remain stubborn. On the point of declaration it won't declare its name qva_Fonts;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef _MAKE_FONTS_H_H
#define _MAKE_FONTS_H_H

#include <glut.h>
#include <cmath>
#include <vector>
.......................................
..........................................................

using namespace std;

  CLetter qCB;

  CLetter1 q1;
 
  CLetter2 q2;
 
  CLetter3 q3;
...........................................
.......................................
vector <CLetter *> qva_Fonts;

qva_Fonts.push_back(q1);	 
You can't push q1 cause you have made qva_Fonts a vector of pointers. It would be enough if you just removed that unnecessary * in your vector declaration.
I made the necessary changes and it wont even give me the opportunity to push_back
I made the necessary changes


If you would have made the necessary changes it would work, wouldn't it? Post your new code.
The same problem still persists, it thinks qvaFonts is an undeclared int, or just uncleared object (this is on the vector declaration).

Plus some extra info, when I mouse over vector<CLetter*> qva_Fonts; (the word vector), I see the message
"class std:: vector::<typename_Ty, typename_Ax>"
.

Whereas when a vector is declared in a main.cpp file vector<CDisplay *> qTile;, I get
"class std:: vector::<CDisplay *, std::allocator<CDisplay *>>"
. This second declaration is from another simple program and it works perfectly. I want my vector to behave like this latter declaring in the main.cpp file but it simple refuses

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
#ifndef _MAKE_FONTS_H_H
#define _MAKE_FONTS_H_H

#include <glut.h>
#include <cmath>
#include <iostream>
#include <vector>
.......................................
..........................................................

using namespace std;

  CLetter qCB;

  CLetter1 q1;
 
  CLetter2 q2;
 
  CLetter3 q3;
...........................................
.......................................
 //*********************************
 //Put fonts classes into pointers
  //*******************************

  CLetter * qPtrCB = &qCB;

  CLetter * qPtr1 = &q1;
 
  CLetter * qPtr2= &q2;
 
  CLetter * qPtr3= &q3;
 
......................................................
..............................................
...........................................

  //assigning fonts to vector
  vector<CLetter*> qva_Fonts;

  qva_Fonts.push_back(qPtr1 ); 
What error is this giving you?
these, I dont have semicolon issues by the way its based on that line
1>------ Build started: Project: Doctor game text, Configuration: Debug Win32 ------
1>Compiling...
1>MakeFont.cpp
1>j:programmingintrogdoctor game textdoctor game textmakefont.h(1566) : error C2143: syntax error : missing ';' before '.'
1>j:programmingintrogdoctor game textdoctor game textmakefont.h(1566) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>j:programmingintrogdoctor game textdoctor game textmakefont.h(1566) : error C2371: 'qva_Fonts' : redefinition; different basic types
1> j:programmingintrogdoctor game textdoctor game textmakefont.h(1564) : see declaration of 'qva_Fonts'
1>Generating Code...
1>Compiling...
1>main.cpp
1>j:programmingintrogdoctor game textdoctor game textmakefont.h(1566) : error C2143: syntax error : missing ';' before '.'
1>j:programmingintrogdoctor game textdoctor game textmakefont.h(1566) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>j:programmingintrogdoctor game textdoctor game textmakefont.h(1566) : error C2371: 'qva_Fonts' : redefinition; different basic types
1> j:programmingintrogdoctor game textdoctor game textmakefont.h(1564) : see declaration of 'qva_Fonts'

basically its still refusing to declare "qva_Fonts" as a vector. It tearing my hair now. I dont know why it works in main but not headers.
Your compiler apparently doesn't know what a vector is at that point. Try putting std:: in front of it.
I've tried but it doesn't work
What I don't really get is, what is this CLetter? And why do you have 4 different CLetter types, but try to stuff all of them into the same vector?
Cletter is a base class for all fonts, thus I have to use it as a pointer. I need to stick all fonts under the same vector for the same of accessing them when I need to draw a character.
Cletter is a base class for all fonts, thus I have to use it as a pointer.


Did you define that yourself, or did you just take over that design? If that was your idea, you'd better give it a second thought. If it's just about different fonts and not whole different types of fonts, you should use the same class for all of them.

Anyways, to your problem:

If your IDE knows what a vector is at that point, your compiler probably does too. Hence the problem is not with the vector, but with the CLetters - do you include the header file in which they are defined in the portion of code you are showing (you sort of censored your code so I can't tell).
Last edited on
yes I did include it, its defined there in the header file.

I even tried to put it into a cpp file for the class but it didn't work. Please can you explain this to me.
Well, I don't think we will make any progress here without knowing the actual file setup here.
this is the extract of the mammoth code as summarized above

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#ifndef _MAKE_FONTS_H_H
#define _MAKE_FONTS_H_H

#include <glut.h>
#include <cmath>
#include <iostream>
#include <vector>
#define PI 3.1415926535898 
GLint circle_points = 145445; 
void MyCircle2f(GLfloat centerx, GLfloat centery, GLfloat radius){
  GLint i;
  GLdouble angle;
  glBegin(GL_POLYGON); 
  for (i = 0; i < circle_points; i++) {    
    angle = 2*PI*i/circle_points; 
    glVertex2f(centerx+radius*cos(angle), centery+radius*sin(angle)); 
  } 
  glEnd();
}

GLfloat RadiusOfBall = 5.;
// Draw the ball, centered at the origin
static void draw_ball() {
  glColor3f(0.6,0.3,0.);
  MyCircle2f(0.,0.,RadiusOfBall);
 }

class CLetter
{
public:
virtual void draw()const
{	draw_ball();
}
};

class CLetter1:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};


class CLetter2:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};

class CLetter3:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};

class CLetter4:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};

class CLetter5:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};

class CLetter6:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};

class CLetter7:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};

class CLetter8:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};

class CLetter9:public CLetter
{
public:
	virtual void draw()const
{	draw_ball();
}
};



//*****************************
//pass font objects to Vector array
//*****************************
//using namespace std;

  CLetter qCB; 

  CLetter1 q1;
 
  CLetter2 q2;
 
  CLetter3 q3;
 
  CLetter4 q4;
 
  CLetter5 q5;
 
  CLetter6 q6;
 
  CLetter7 q7;
 
  CLetter8 q8;
 
  CLetter9 q9;
 
  CLetter10 q10;
 
 //*********************************
 //Put fonts classes into pointers
  //*******************************

  CLetter * qPtrCB = &qCB;

  CLetter * qPtr1 = &q1;
 
  CLetter * qPtr2= &q2;
 
  CLetter * qPtr3= &q3;
 
  CLetter * qPtr4= &q4;
 
  CLetter * qPtr5= &q5;
 
  CLetter * qPtr6= &q6;
 
  CLetter * qPtr7= &q7;
 
  CLetter * qPtr8= &q8;
 
  CLetter * qPtr9= &q9;
 
  CLetter * qPtr10= &q10;
 
 
  //assigning fonts to vector
  std::vector<CLetter *> qva_Fonts;

  qva_Fonts.push_back(qPtrCB);
  qva_Fonts.push_back(qPtr1);
  
  qva_Fonts.push_back(qPtr2);
  qva_Fonts.push_back(qPtr3);
  qva_Fonts.push_back(qPtr4);
  qva_Fonts.push_back(qPtr5);
  qva_Fonts.push_back(qPtr6);
  qva_Fonts.push_back(qPtr7);
  qva_Fonts.push_back(qPtr8);
  qva_Fonts.push_back(qPtr9);
 
 
 
#endif 
why are lines 115 - 180 not inside any function?
I was going to use this header file in another header file (drawFonts.h) which would draw the fonts created from this header file (make fonts.h).

I had to edits bits because of length
Last edited on
Pages: 12