I could of sworn you could get the value of a static member of a class using
this syntax "class::member" but my compliler is complaining. How can I do
what I am trying to do here besides making a function for it. Isnt there a
short easy way? Oh and my instructor wont let me use a #define because he is
a terd.
the header:
class BigPosInt
{
public:
static const int MAX_DIGITS = 30;
// snip...
};
the function in question:
void input(istream& ins, BigPosInt& targetBpi)
{
int counter = 0;
char one_byte;
int buffer[BigPosInt::MAX_DIGITS];
// snip..
}
the error:
BigPosInt.cpp:170: `MAX_DIGITS' undeclared (first use this function)
Thanx,
Christopher 10 3262
On Sun, 14 Sep 2003 06:09:53 GMT in comp.lang.c++ : class BigPosInt { public: static const int MAX_DIGITS = 30; // snip... };
the function in question:
BigPosInt.cpp:170: `MAX_DIGITS' undeclared (first use this function)
Your compiler is wrong.... as a work around define it
outside the class declaration, see if it'll fly that way.
(I.e.)
const int BigPosInt::MAX_DIGITS = 30;
--
Regards...
Bill
On Sun, 14 Sep 2003 07:48:25 GMT in comp.lang.c++ : On Sun, 14 Sep 2003 06:09:53 GMT in comp.lang.c++ :
BigPosInt.cpp:170: `MAX_DIGITS' undeclared (first use this function)
Your compiler is wrong.... as a work around define it outside the class declaration, see if it'll fly that way.
Actually I am wrong, just browsed the standard.
A static const data member can be initialized in the
declaration (integral type), but if it used "in" the
program "it shall" still be defined in namespace scope"
and the definition "shall not" contain an initializer.
(9.4.2-4)
so the way I read it ;
class A {
public:
static const int AINT = 30;// initialized and declared
};
// this case global namespace
const int A::AINT; // defined ?
Apologize for the bad advice....
--
Regards...
Bill
"Percy" <Pe***@noemail.given> wrote in message
news:MP************************@news.prodigy.net.. . On Sun, 14 Sep 2003 07:48:25 GMT in comp.lang.c++ :
Actually I am wrong, just browsed the standard. A static const data member can be initialized in the declaration (integral type), but if it used "in" the program "it shall" still be defined in namespace scope" and the definition "shall not" contain an initializer. (9.4.2-4)
If I understand this correctly, it is pointless to make such a member
public. You are quite welcome to place the initializer in the class
definition. Just don't use it in the program.
I thought this was one of the few additions to the standard that Stroustrup
disagreed with, and it's no wonder.
DW
"David White" <no.email@provided> wrote in message
news:K8******************@nasal.pacific.net.au... I thought this was one of the few additions to the standard that
Stroustrup disagreed with, and it's no wonder.
Allowing the initializer in the class definition at all, I meant, not the
conditions on its use.
DW
Percy wrote in news:MP************************@news.prodigy.net: On Sun, 14 Sep 2003 07:48:25 GMT in comp.lang.c++ :
On Sun, 14 Sep 2003 06:09:53 GMT in comp.lang.c++ :
> > BigPosInt.cpp:170: `MAX_DIGITS' undeclared (first use this function)
Your compiler is wrong.... as a work around define it outside the class declaration, see if it'll fly that way.
Actually I am wrong, just browsed the standard. A static const data member can be initialized in the declaration (integral type), but if it used "in" the program "it shall" still be defined in namespace scope" and the definition "shall not" contain an initializer. (9.4.2-4)
so the way I read it ;
class A { public: static const int AINT = 30;// initialized and declared }; // this case global namespace const int A::AINT; // defined ?
Apologize for the bad advice....
You may want to see: http://anubis.dkuug.dk/jtc1/sc22/wg2...efects.html#48
issue 48. Definitions of unused static members
This issue has status TC1 so IIUC its resolution to allow the
OP's original code is Standard C++.
Rob.
-- http://www.victim-prime.dsl.pipex.com/
"David White" <no.email@provided> wrote in message
news:K8******************@nasal.pacific.net.au... "Percy" <Pe***@noemail.given> wrote in message news:MP************************@news.prodigy.net.. . On Sun, 14 Sep 2003 07:48:25 GMT in comp.lang.c++ :
Actually I am wrong, just browsed the standard. A static const data member can be initialized in the declaration (integral type), but if it used "in" the program "it shall" still be defined in namespace scope" and the definition "shall not" contain an initializer. (9.4.2-4) If I understand this correctly, it is pointless to make such a member public. You are quite welcome to place the initializer in the class definition. Just don't use it in the program.
I thought this was one of the few additions to the standard that
Stroustrup disagreed with, and it's no wonder.
DW
I would of done things much differantly, but this is my instructors header
file and I am not allowed to change it at all, the whole thing is done very
badly.
,
Chris
Christopher wrote: I could of sworn you could get the value of a static member of a class using this syntax "class::member" but my compliler is complaining. How can I do what I am trying to do here besides making a function for it. Isnt there a short easy way?
There's nothing wrong with the code you posted. So either your compiler
doesn't support this properly or the code you posted is different from
the actual code.
Oh and my instructor wont let me use a #define because he is a terd.
Lose the attitude. It's quite likely that your instructor knows more
about what he's trying to accomplish than you do.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
"Pete Becker" <pe********@acm.org> wrote in message
news:3F**************@acm.org... Christopher wrote: I could of sworn you could get the value of a static member of a class
using this syntax "class::member" but my compliler is complaining. How can I
do what I am trying to do here besides making a function for it. Isnt there
a short easy way? There's nothing wrong with the code you posted. So either your compiler doesn't support this properly or the code you posted is different from the actual code.
Found that the :: operation works fine on another compiler. You are correct.
Frustrating how one feature works on one compiler, but another feature does
not. Oh and my instructor wont let me use a #define because he is a terd.
Lose the attitude. It's quite likely that your instructor knows more about what he's trying to accomplish than you do.
Well I would give a list of reasons why the attitude was developed, but I
hardly think anyone cares. Let's just say that I am sure I am justified in
my opinion.
--
Pete Becker Dinkumware, Ltd. (http://www.dinkumware.com)
"Christopher" <cp***@austin.rr.com> wrote in message
news:RC******************@twister.austin.rr.com... I could of sworn...
You could HAVE sworn...
... you could get the value of a static member of a class using this syntax "class::member" but my compliler is complaining.
Let me guess, Visual C++?
Oh and my instructor wont let me use a #define because he is a terd.
He is a TURD, not terd. And that remains to be seen. I wouldn't let you
use #define either.
jeffc wrote: "Christopher" <cp***@austin.rr.com> wrote in message news:RC******************@twister.austin.rr.com... I could of sworn...
You could HAVE sworn...
... you could get the value of a static member of a class using this syntax "class::member" but my compliler is complaining.
Let me guess, Visual C++?
Probably not. VC++ complains at the point of definition.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Joost Ronkes Agerbeek |
last post by:
Why is it allowed in C++ to call a static member function of an object
through an instance of that object? Is it just convenience?
tia,
Joost Ronkes Agerbeek
|
by: Mike Hewson |
last post by:
Have been researching as to why:
<example 1>
class ABC
{
static const float some_float = 3.3f;
};
<end example 1>
|
by: Srini |
last post by:
Hello all,
I was just wondering about this. A const member function guarantees
constness of the object within the function body. But there's no way
for a member function to guarantee the...
|
by: asianmuscle |
last post by:
I am trying to learn RAII and some template techniques by writer a
smarter pointer class to manage the resource management. Since I find
that a lot of the resource management is kinda the same, I...
|
by: mast2as |
last post by:
Hi guys
Here's the class I try to compile (see below). By itself when I have a
test.cc file for example that creates an object which is an instance of
the class SpectralProfile, it compiles...
|
by: John Goche |
last post by:
Hello,
I would like to know whethere there is a difference between
a const variable and a static const variable inside a class.
After all, if a variable is const in a class, the compiler can...
|
by: davydany |
last post by:
Hey guys...a n00b Here for this site.
I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
|
by: subramanian100in |
last post by:
why can't a static member function be declared as const ? We can
declare a non-static member function as const, to indicate that it
does not modify the non-mutable data members. In the same way, is...
|
by: akomiakov |
last post by:
Is there a technical reason why one can't initialize a cost static non-
integral data member in a class?
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |