0

Can somebody tell me what is the difference between static class and static local variable in C++ ?

u will be greatful if u explain it giving example

thanking you

4
Contributors
5
Replies
12
Views
9 Years
Discussion Span
Last Post by vijayan121
0

C++ doesn't directly support a static class. Are you talking about a class that only has static members and doesn't have a public constructor?

0

C++ doesn't directly support a static class. Are you talking about a class that only has static members and doesn't have a public constructor?

yes

0

A static local variable retains its value between calls of the function. A static class has data that retains values between uses of the class and methods that act on the data. It's hard to compare the two because they're not really comparable. A static data member is like a static local variable on steroids though. :)

0

static local variables and static data members have lifetimes like global variables (there is only one copy in the program, and it exists for the whole duration of the program), except that their scope is not global

0

> Are you talking about a class that only has static members and doesn't have a public constructor?
>> yes

that is the java style of programming. in C++, using a namespace for this purpose is canonical.

class foo
{
  foo() ;
  public:
   static int f() ;
   static double value ;
};
namespace foo
{
   int f() ;
   extern double value ;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.