How can I do the following?
class C{
private:
static const char c[3] = {1,2,3};
//...
};
The compiler says it can't be done like that. 6 15680
Hello,
"RCAJ" <rc******@teleline.es> wrote in message
news:Dl***********************@telenews.teleline.e s... How can I do the following?
class C{ private: static const char c[3] = {1,2,3}; //... };
The compiler says it can't be done like that.
Static variables should be initialized from outside class.
--
Elias
RCAJ wrote: How can I do the following?
class C{ private: static const char c[3] = {1,2,3}; //... };
The compiler says it can't be done like that.
Yeah, those up-tight compilers can be really retentive, you know?
class C
{
static const char c[ 3 ];
};
const char C::c[ 3 ] = { 1, 2, 3 }; Static variables should be initialized from outside class.
-- Elias
how?
I just want const values for that array. How can I initialize it so that
when I create an object the values are ready to be used without
initializing them in the constructor?
Jeff Schwab escribió: RCAJ wrote:
How can I do the following?
class C{ private: static const char c[3] = {1,2,3}; //... };
The compiler says it can't be done like that.
Yeah, those up-tight compilers can be really retentive, you know?
class C { static const char c[ 3 ]; };
const char C::c[ 3 ] = { 1, 2, 3 };
Thanks. It already works! But I've got a question: why can I get access
to a private atribute outside the class?
"Alexandros" <em***@company.com> wrote... [...] Thanks. It already works! But I've got a question: why can I get access to a private atribute outside the class?
Probably because it's _private_...
Alexandros wrote: class C{ private: static const char c[3] = {1,2,3}; //... };
<snip/>
class C { static const char c[ 3 ]; };
const char C::c[ 3 ] = { 1, 2, 3 };
Thanks. It already works! But I've got a question: why can I get access to a private atribute outside the class?
You're not really accessing it, you're still defining and initializing
it. The semantics are the same as for any private method. You can
define it outside the class. The defintion doesn't count as an access.
You're not actualling calling the method, or in this case, accessing
the variable.
-Jeff This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Makis Papapanagiotou |
last post by:
Hello,
I really don't understand the simplest thing at the moment. I have a static
array of pointers to a class . How do we initialize it?
class classA
{
public:
int x1;
};
|
by: Avner Flesch |
last post by:
Hi,
Do you know how can I intialize an array member:
for example
class A
{
public:
A(int x);
};
|
by: zoe |
last post by:
Is it possible to initialize a non-static const array class-member of
a fundamental type?
Something like:
class Foo{}{
public:
Foo();
private:
const int myArray;
|
by: slack_justyb |
last post by:
Hello,
I'm trying to figure the best way of doing the following.
*I need an array of strings that are globally accessable from within
'arrayhere.h'
*I need that array of strings to not change...
|
by: Charles Sullivan |
last post by:
Assume I have a static array of structures the elements of which
could be any conceivable mixture of C types, pointers, arrays.
And this array is uninitialized at program startup.
If later in...
|
by: subramanian |
last post by:
I am a beginner in C++.
Suppose I want to build a class: I have given below the starting code:
class Date {
int day, month, year;
static Date default_date;
};
|
by: Vol |
last post by:
Hi, Group,
I want to initialize a 2D static array in function 'foo ()', where
'foo' is called by another function a lot of times.
I list my implementation below but I think there are better...
|
by: Bram Kuijper |
last post by:
Hi all,
as a C++ newbie, I got some question on the initialization of static
reference data members.
Since it isn't possible to initialize static members of a class in the
constructor, I...
|
by: flowstudioLA |
last post by:
I have a template class object that I use as a mesaging queue between
threads. I use it as a static object that I initialize like so:
foo.h
class foo{
static LFQueue<const char*,100lfqMyQueue;...
|
by: Bob Altman |
last post by:
Hi all,
I have a class that contains a member variable that is an array of class
instances:
class MyClass {
private:
SomeClass m_someClass;
SomeClass m_arrayOfClasses;
};
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |