Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > anonymous namespaces and scope resolution question

Reply
Thread Tools

anonymous namespaces and scope resolution question

 
 
2b|!2b==?
Guest
Posts: n/a
 
      04-26-2007
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" ?
 
Reply With Quote
 
 
 
 
Serge Skorokhodov
Guest
Posts: n/a
 
      04-26-2007
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" ?

 
Reply With Quote
 
 
 
 
anon
Guest
Posts: n/a
 
      04-26-2007
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" ?

 
Reply With Quote
 
2b|!2b==?
Guest
Posts: n/a
 
      04-26-2007


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"
 
Reply With Quote
 
anon
Guest
Posts: n/a
 
      04-26-2007
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
 
Reply With Quote
 
SMHealthNick
Guest
Posts: n/a
 
      04-26-2007
On Apr 26, 9:32 am, anon <(E-Mail Removed)> 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

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      04-27-2007
"2b|!2b==?" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anonymous namespaces and friend functions Ronald Raygun C++ 5 04-02-2008 08:14 AM
Is this a local anonymous class or a member anonymous class Reporter Java 3 05-12-2007 05:23 AM
Scope resolution operator question Jack C++ 6 05-12-2006 06:00 AM
Newcomer question wrt variable scope/namespaces Florian Daniel Otel Python 8 01-18-2006 01:02 PM
help with an anonymous array of anonymous hashes noeldamonmiller@gmail.com Perl Misc 1 02-10-2005 01:08 AM



Advertisments