473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

anonymous namespaces and scope resolution question

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" ?
Apr 26 '07 #1
6 2174
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" ?
Apr 26 '07 #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 ;
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" ?
Apr 26 '07 #3


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"
Apr 26 '07 #4
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
Apr 26 '07 #5
On Apr 26, 9:32 am, anon <a...@no.nowrote:
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

Apr 26 '07 #6
"2b|!2b==?" <ro**@your.box.comwrote in message
news:Ba******************************@bt.com...
>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.
Apr 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Marcin Vorbrodt | last post by:
Here is an example of my code: //Header file #include <vector> using std::vector; namespace Revelation { // class definitions, etc... // class members are of type std::vector }
21
by: Blue Ocean | last post by:
Forgive me for asking so many questions so quickly. I am simply asking as they come up unanswered in my book. Can you change namespaces half way through a file? For instance, if you want to...
15
by: Stuart | last post by:
I work in a small company with developers who do not like to use "new" features when they find the old ones sufficient. e.g. given a choice between a class and a namespace, they'll pick class. ...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
8
by: Florian Daniel Otel | last post by:
Hello all, As the subject says, I am a newcomer to Python and I have a newcomer question wrt namespaces and variable scope. Obviously, I might be missing smth obvious, so TIA for the patience...
6
by: Jack | last post by:
I want to write code that can be compiled as C and C++. In the Windows API, there are many macros that help with scope resolution. For example: #ifdef __cplusplus #define SNDMSG ::SendMessage...
2
by: Gabe Moothart | last post by:
Hello, In one of my asp.net applications, I create a series of checkboxes, set their properties, and give them an "onChecked" event handler on the fly using an anonymous method. The code looks...
6
by: =?Utf-8?B?TUNN?= | last post by:
What is the difference between importing a namespace at the: 1. Project level 2. web.config level 3. Page level What are the requirements/benefits of each? If I import a namespace such as...
22
by: Luna Moon | last post by:
I am reading the book "C++ Annotations", and here is a quote from the book: Namespaces can be defined without a name. Such a namespace is anonymous and it restricts the visibility of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.