anonymous namespaces and scope resolution question

Discussion in 'C++' started by 2b|!2b==?, Apr 26, 2007.

  1. 2b|!2b==?

    2b|!2b==? Guest

    I have the following declaration in a header file (MyClass.h)

    //contents of MyClass.h
    class MyClass
    {
    public:
    MyClass()
    MyClass(const MyClass&);
    ...
    };
    typedef std::vector<MyClass> MyClassVect;
    typedef MyClassVect::iterator MyClassVectIter;
    typedef MyClassVect::const_iterator MyClassVectConstIter;



    //Contents of souce file (AnotherFile.cpp)
    #include "MyClass.h"

    namespace
    {
    MyClassVector classes ;
    classes.push_back(new MyClass()); //syntax error : missing ';' before '.'
    .......
    }

    The type of variable 'classes' is not recognized as a vector (as
    specified in the declaration), but rather as an int (i.e. int
    'anonymous-namespace'::classes).

    question is - how may I use a variable of the types declared in
    "MyClass.h" ?
     
    2b|!2b==?, Apr 26, 2007
    #1
    1. Advertising

  2. 2b|!2b==? wrote:
    > I have the following declaration in a header file (MyClass.h)
    >
    > //contents of MyClass.h
    > class MyClass
    > {
    > public:
    > MyClass()
    > MyClass(const MyClass&);
    > ..
    > };
    > typedef std::vector<MyClass> MyClassVect;
    > typedef MyClassVect::iterator MyClassVectIter;
    > typedef MyClassVect::const_iterator MyClassVectConstIter;
    >
    >
    >
    > //Contents of souce file (AnotherFile.cpp)
    > #include "MyClass.h"
    >
    > namespace
    > {
    > MyClassVector classes ;
    > classes.push_back(new MyClass()); //syntax error : missing ';' before '.'
    > .......
    > }


    I'm afraid you can place only declarations inside a namespace (whether
    anonymous or not).

    > The type of variable 'classes' is not recognized as a vector (as
    > specified in the declaration), but rather as an int (i.e. int
    > 'anonymous-namespace'::classes).
    >
    > question is - how may I use a variable of the types declared in
    > "MyClass.h" ?
     
    Serge Skorokhodov, Apr 26, 2007
    #2
    1. Advertising

  3. 2b|!2b==?

    anon Guest

    2b|!2b==? wrote:
    > I have the following declaration in a header file (MyClass.h)
    >
    > //contents of MyClass.h
    > class MyClass
    > {
    > public:
    > MyClass()
    > MyClass(const MyClass&);
    > ..
    > };
    > typedef std::vector<MyClass> MyClassVect;
    > typedef MyClassVect::iterator MyClassVectIter;
    > typedef MyClassVect::const_iterator MyClassVectConstIter;
    >
    >
    >
    > //Contents of souce file (AnotherFile.cpp)
    > #include "MyClass.h"
    >
    > namespace
    > {
    > MyClassVector classes ;


    Can you mark the line where you declared/defined MyClassVector?


    > classes.push_back(new MyClass()); //syntax error : missing ';' before '.'
    > .......
    > }
    >
    > The type of variable 'classes' is not recognized as a vector (as
    > specified in the declaration), but rather as an int (i.e. int
    > 'anonymous-namespace'::classes).
    >
    > question is - how may I use a variable of the types declared in
    > "MyClass.h" ?
     
    anon, Apr 26, 2007
    #3
  4. 2b|!2b==?

    2b|!2b==? Guest

    anon wrote:

    > 2b|!2b==? wrote:
    >
    >> I have the following declaration in a header file (MyClass.h)
    >>
    >> //contents of MyClass.h
    >> class MyClass
    >> {
    >> public:
    >> MyClass()
    >> MyClass(const MyClass&);
    >> ..
    >> };
    >> typedef std::vector<MyClass> MyClassVect;
    >> typedef MyClassVect::iterator MyClassVectIter;
    >> typedef MyClassVect::const_iterator MyClassVectConstIter;
    >>
    >>
    >>
    >> //Contents of souce file (AnotherFile.cpp)
    >> #include "MyClass.h"
    >>
    >> namespace
    >> {
    >> MyClassVector classes ;

    >
    >
    > Can you mark the line where you declared/defined MyClassVector?
    >


    That was a typo. MyClassVector should read MyClassVect in the source
    file "AnotherFile.cpp"
     
    2b|!2b==?, Apr 26, 2007
    #4
  5. 2b|!2b==?

    anon Guest

    2b|!2b==? wrote:
    >
    >
    > anon wrote:
    >
    >> 2b|!2b==? wrote:
    >>
    >>> I have the following declaration in a header file (MyClass.h)
    >>>
    >>> //contents of MyClass.h
    >>> class MyClass
    >>> {
    >>> public:
    >>> MyClass()
    >>> MyClass(const MyClass&);
    >>> ..
    >>> };
    >>> typedef std::vector<MyClass> MyClassVect;
    >>> typedef MyClassVect::iterator MyClassVectIter;
    >>> typedef MyClassVect::const_iterator MyClassVectConstIter;
    >>>
    >>>
    >>>
    >>> //Contents of souce file (AnotherFile.cpp)
    >>> #include "MyClass.h"
    >>>
    >>> namespace
    >>> {
    >>> MyClassVector classes ;

    >>
    >>
    >> Can you mark the line where you declared/defined MyClassVector?
    >>

    >
    > That was a typo. MyClassVector should read MyClassVect in the source
    > file "AnotherFile.cpp"


    Sorry, but I do not see how MyClassVector reads MyClassVect, and your
    example does not compile to show that.

    Maybe someone else see whats going on there
     
    anon, Apr 26, 2007
    #5
  6. 2b|!2b==?

    SMHealthNick Guest

    On Apr 26, 9:32 am, anon <> wrote:
    > 2b|!2b==? wrote:
    >
    > > anon wrote:

    >
    > >> 2b|!2b==? wrote:

    >
    > >>> I have the following declaration in a header file (MyClass.h)

    >
    > >>> //contents of MyClass.h
    > >>> class MyClass
    > >>> {
    > >>> public:
    > >>> MyClass()
    > >>> MyClass(const MyClass&);
    > >>> ..
    > >>> };
    > >>> typedef std::vector<MyClass> MyClassVect;
    > >>> typedef MyClassVect::iterator MyClassVectIter;
    > >>> typedef MyClassVect::const_iterator MyClassVectConstIter;

    >
    > >>> //Contents of souce file (AnotherFile.cpp)
    > >>> #include "MyClass.h"

    >
    > >>> namespace
    > >>> {
    > >>> MyClassVector classes ;

    >
    > >> Can you mark the line where you declared/defined MyClassVector?

    >
    > > That was a typo. MyClassVector should read MyClassVect in the source
    > > file "AnotherFile.cpp"

    >
    > Sorry, but I do not see how MyClassVector reads MyClassVect, and your
    > example does not compile to show that.
    >
    > Maybe someone else see whats going on there- Hide quoted text -
    >
    > - Show quoted text -


    good point
     
    SMHealthNick, Apr 26, 2007
    #6
  7. 2b|!2b==?

    Jim Langston Guest

    "2b|!2b==?" <> wrote in message
    news:...
    >I have the following declaration in a header file (MyClass.h)
    >
    > //contents of MyClass.h
    > class MyClass
    > {
    > public:
    > MyClass()
    > MyClass(const MyClass&);
    > ..
    > };
    > typedef std::vector<MyClass> MyClassVect;
    > typedef MyClassVect::iterator MyClassVectIter;
    > typedef MyClassVect::const_iterator MyClassVectConstIter;
    >
    >
    >
    > //Contents of souce file (AnotherFile.cpp)
    > #include "MyClass.h"
    >
    > namespace
    > {
    > MyClassVector classes ;
    > classes.push_back(new MyClass()); //syntax error : missing ';' before
    > '.'
    > .......
    > }
    >
    > The type of variable 'classes' is not recognized as a vector (as specified
    > in the declaration), but rather as an int (i.e. int
    > 'anonymous-namespace'::classes).
    >
    > question is - how may I use a variable of the types declared in
    > "MyClass.h" ?


    Too many problems with this code to say what is going on as others have
    pointed out. Please provide compilable (even with the error) code that
    demonstrates the problem.
    1. MyClassVect != MyClassVector
    2. classes.push_back... executable code outside a function body.
    3. no main.
     
    Jim Langston, Apr 27, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    1,009
    Andrew FPGA
    Sep 26, 2005
  2. Jack
    Replies:
    6
    Views:
    574
  3. Reporter
    Replies:
    3
    Views:
    496
    Mike Schilling
    May 12, 2007
  4. Ronald Raygun
    Replies:
    5
    Views:
    519
    James Kanze
    Apr 2, 2008
  5. Replies:
    1
    Views:
    239
Loading...

Share This Page