"namespace" and "class"

J

janek

I have a question:

what differences are between:


namespace Mary {

int r = 5 ;

char m[r] ;

void print1() ;

}


and


class Mary {
private :
int r = 5 ;
char m[r] ;

public :
Mary();
~Mary() ;
void print1() ;
}


excluding "private", "public", contructor and destructor in "class Mary" ?
Generally: what differences are between using declaration of "namespace"
and "class" ?
 
P

Phil Staite

In the class case, members m and r are not visible outside the class.
However, in the namespace case, m and r *are* visible to anyone
accessing the namespace.

Also, the namespace variant will create global m and r, the class case
has them as instance data.
 
A

Athresh

This program does not work as as c++ doesnot support variable sizeof
arrays like that.

Athresh
 
A

athresh

This program does not work as it has a variable array inside the
namespace which is neither supported in c or c++
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top