typedef scope!?

This is probably something quite simple, but I'm having trouble declaring a typedef in my namespace scope. Here's a simplified example:

1
2
3
4
5
// typedefs.h
namespace MyProject
{
  typedef void (A::B::*p_type_simple_function)();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
// class_a.h
#include "typedefs.h"
namespace MyProject
{
  class A
  {
    // some constructors, functions, variables, etc. for A
    class B
    {
      p_type_simple_function arr_fun [];
// error: static <error-type> MyProject::A::B::arr_fun[] array of functions is not allowed
    }
  }
}


Adding the typedef just prior to the declaration fixes the issue, so it seems to be some scoping/namespace problem that I just can't figure out:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// class_a.h
namespace MyProject
{
  class A
  {
    // some constructors, functions, variables, etc. for A
    class B
    {
      typedef void (A::B::*p_type_simple_function)();
      p_type_simple_function arr_fun [];
      // the above works fine
    }
  }
}


(I've written this code for the sake of this forum post so please don't mind the typos if any)
Last edited on
closed account (zb0S216C)
ausairman wrote:
1
2
3
4
namespace MyProject
{
  typedef void (A::B::*p_type_simple_function)();
}

Was this before or after the declaration of "A::B"?

Wazzak
... After. Thanks.

closed account (zb0S216C)
ausairman wrote:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// class_a.h
#include "typedefs.h"
namespace MyProject
{
  class A
  {
    // some constructors, functions, variables, etc. for A
    class B
    {
      p_type_simple_function arr_fun [];
// error: static <error-type> MyProject::A::B::arr_fun[] array of functions is not allowed
    }
  }
}

This shouldn't even compile, let alone give you: "error: static <error-type> MyProject::A::B::arr_fun[] array of functions is not allowed".

Because the declaration of "MyProject::p_type_simple_function" appears before the declaration of both "A" and "B", the compiler should complain about "A" and "B" not being declared.

When "p_type_simple_function" is declared inside of "B's" scope, the compiler knows that both "A" and "B" exists, which is why your third code snippet compiles.

Wazzak
Last edited on
Topic archived. No new replies allowed.