Scopes problem...

Hi,

My compiler replies me with an error that I don't know how solve. It says me that "A is not declared in this scope"

I've an structure,

struct A
{
bool b;
int c;
};

That I'm trying to use it in class scopes in order to create vectors like this...

#include <vector>

class MyClassA
{
(...)
private:
std::vector <A> my_vector_a;
};

S.
A is an #include dependency for MyClassA

Therefore myclassa.h needs to include a.h (or whatever header defines the A struct).


EDIT: actually you probably can just forward declare it. Put struct A; above the MyClassA body (next to your #include <vector> line)

/EDIT

See section 4 of this article:

http://www.cplusplus.com/forum/articles/10627/#msg49679
Last edited on
Not yet...

Here goes my test code...

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
#include <vector>

struct A
{
   bool b;
   int c;
};

class ClassA
{
public:
   ClassA()
      {my_vector_A.resize (10);}
   ~ClassA(){}

private:
   struct A;
   std::vector <A> my_vector_A;
};

int main (int argc, char *argv[])
{
   ClassA my_object_A;
   return 0;
}


The compiler throws me some error messages !!!
Last edited on
Sorry, I may have been unclear.

Get rid of line 17. If struct A is defined before ClassA, you don't need to forward declare it.
Topic archived. No new replies allowed.