Original Post
Hi
Question 1.
I am confused about one thing. What I was trying to do is to get rid of a class declaration CFoo declared in Foo.h (see code below) and just use namespace MY. so in main program I would not have to create an object of CFoo class declared in Foo.h but I could directly access functions declared in namespace MY in Foo.h ie.
void main()
{
MY::Open( "file.txt" );
MY::Close();
}
as this is just what I need. I dont need to create an object of class CFoo which I would like to be static anyway so there is no advantage of using class as all my member I want to be static in that namespace. But if I get rid of class declaration then in the Foo.h file where the namespace is declared all variables (used inside Open() Close() function) will be global but I would like them to be hidden from user so when you type MY:: only functions Open() and Close will popup in visual studio and those should be only visiable but not other internal variables declared in same namespace MY.
Now if I uncomment the CFoo class declaration then all those functions Open() etc.. CFoo class will be public and variables used by these function as private. They would be hidden from the user. This is the only reason I am trying to put this code into class otherwise I would not declare a class for it.
So I tried to do this (with class declaration):
Why this doesnt compile?
typedef static std::vector names;
the error is:
error C2159: more than one storage class specified
[edited by - papa on May 31, 2004 8:05:51 AM]
#ifndef _FOO_H_ // we are in Foo.h file
#define _FOO_H_
#include <vector>
using namespace std;
typedef vector<char*> TestNames; // Mthod 1, <--- THIS WORKS
typedef static vector<char*> TestNames; //Method 2, <--- THIS WAY DOESNT WORK
______________________________________
namespace MY
{
class CFoo
{
public:
// No constructor and no destructor in this class
static void Open();
static void Close();
private:
TestNames names; // ok with METHOD 1 but its not static
static TestNames names; // This way doesnt work with METHOD 2
};
};#endif
Is there any solution for this problem. The ideal thing would be to comment out the class declaration and just use the namspace on its own but the internal vars are public which is not what I want.:
#ifndef _FOO_H_ // we are in Foo.h file
#define _FOO_H_
#include <vector>
using namespace std;
typedef vector<char*> TestNames;
______________________
namespace MY
{
// Are all these functions and variables below static?
// Surely they're global. Arent they?
void Open();
void Close();
// Variable below should be hidden but in this case its not.
//Its public. How can I hide it?
TestNames names;
};#endif
Question 2. Typedef problem again