* RE: static memeber initialization in constructor??
@ 2004-11-01 20:25 lrtaylor
2004-11-19 0:04 ` Question on derived class? Ishwar Rattan
0 siblings, 1 reply; 6+ messages in thread
From: lrtaylor @ 2004-11-01 20:25 UTC (permalink / raw)
To: ishwar, gcc-help
You actually have to also define 'one' someone in your implementation
code just like you do your functions:
long A::one[MAX];
That actually causes space to be allocated for 'one'. The declaration
just declares it (kind of like when you use 'extern' - you have to have
it actually defined someone).
Thanks,
Lyle
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Ishwar Rattan
Sent: Monday, November 01, 2004 1:25 PM
To: gcc-help@gcc.gnu.org
Subject: static memeber initialization in constructor??
g++ 3.2.2 under Linux Mandrake-9.1
I have a class A being derived from base class B
class A: public B
{
public:
A() : B("starter") { init_one(); }
// other public methods..
protected:
const int MAX = 10;
static long one[MAX];
static void init_one()
{
for(int i = 0; i < MAX; i++)
one[i] = 9;
}
};
Whem compiled the ld fails with message that there is undefined
reference to
A::one
So, can one initialize a static member in the above scenario?
-ishwar
^ permalink raw reply [flat|nested] 6+ messages in thread
* Question on derived class?
2004-11-01 20:25 static memeber initialization in constructor?? lrtaylor
@ 2004-11-19 0:04 ` Ishwar Rattan
2004-11-19 0:20 ` Eljay Love-Jensen
0 siblings, 1 reply; 6+ messages in thread
From: Ishwar Rattan @ 2004-11-19 0:04 UTC (permalink / raw)
To: gcc-help
Assume that A is pure virtual class with some public
methods.
B is derived from A
Class B : virtual A {
public:
// all methods of A are defined here +
A new method is also defined (here only)
-- call it reset()
protected:
// ...
};
Now B is initiated as
static B b;
A *a = b;
Is it possible to access b.reset() using a->reset()?
-ishwar
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question on derived class?
2004-11-19 0:04 ` Question on derived class? Ishwar Rattan
@ 2004-11-19 0:20 ` Eljay Love-Jensen
0 siblings, 0 replies; 6+ messages in thread
From: Eljay Love-Jensen @ 2004-11-19 0:20 UTC (permalink / raw)
To: Ishwar Rattan, gcc-help
Hi Ishwar,
Your question is a general C++ question, and off-topic for this forum.
>Is it possible to access b.reset() using a->reset()?
Yes.
HTH,
--Eljay
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Question on derived class?
@ 2004-11-19 10:55 Pradip Singh
0 siblings, 0 replies; 6+ messages in thread
From: Pradip Singh @ 2004-11-19 10:55 UTC (permalink / raw)
To: Ishwar Rattan, gcc-help
Hi All,
It is possible to access a->reset() by runtime polymorphism concept in c++. But in ur code the assignment A *a = b is wrong. It should be A *a = &b; But I donot know what u mean by pure virtual class. If it is a class contianing some pure virtual methods then it is called abstract class. And remember to define the pure virtual functions in A in b. Otherwise B will also become abstract class and u cannot create its object. So the very statement static B b; will start throwing compilation error.
But this is not the right forum to ask such question. Find some other C++ forum.
thanks and regards,
Pradip
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]On
Behalf Of Ishwar Rattan
Sent: Friday, November 19, 2004 5:40 AM
To: gcc-help@gcc.gnu.org
Subject: Question on derived class?
Assume that A is pure virtual class with some public
methods.
B is derived from A
Class B : virtual A {
public:
// all methods of A are defined here +
A new method is also defined (here only)
-- call it reset()
protected:
// ...
};
Now B is initiated as
static B b;
A *a = b;
Is it possible to access b.reset() using a->reset()?
-ishwar
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Question on derived class?
[not found] ` <363801FFD7B74240A329CEC3F7FE4CC4030964F6@ntxboimbx07.micro n.com>
@ 2004-11-19 1:02 ` Eljay Love-Jensen
0 siblings, 0 replies; 6+ messages in thread
From: Eljay Love-Jensen @ 2004-11-19 1:02 UTC (permalink / raw)
To: lrtaylor, ishwar, gcc-help
Hi Lyle,
>How is that possible, since 'A' does not have a reset method in it?
It is possible. By putting the virtual reset() method in the A interface
class.
(Obviously, I didn't go into details as to the implementation. Ishwar's
question only asked if it was possible or not.)
>Shouldn't only methods defined in 'A' be able to be called on 'a'?
Correct. :-)
Sincerely,
--Eljay
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Question on derived class?
@ 2004-11-19 0:22 lrtaylor
[not found] ` <363801FFD7B74240A329CEC3F7FE4CC4030964F6@ntxboimbx07.micro n.com>
0 siblings, 1 reply; 6+ messages in thread
From: lrtaylor @ 2004-11-19 0:22 UTC (permalink / raw)
To: eljay, ishwar, gcc-help
How is that possible, since 'A' does not have a reset method in it? At
the time he tries to call a->reset(), the compiler won't know the method
can be called. Shouldn't only methods defined in 'A' be able to be
called on 'a'?
Thanks,
Lyle
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Eljay Love-Jensen
Sent: Thursday, November 18, 2004 5:20 PM
To: Ishwar Rattan; gcc-help@gcc.gnu.org
Subject: Re: Question on derived class?
Hi Ishwar,
Your question is a general C++ question, and off-topic for this forum.
>Is it possible to access b.reset() using a->reset()?
Yes.
HTH,
--Eljay
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-11-19 10:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-01 20:25 static memeber initialization in constructor?? lrtaylor
2004-11-19 0:04 ` Question on derived class? Ishwar Rattan
2004-11-19 0:20 ` Eljay Love-Jensen
2004-11-19 0:22 lrtaylor
[not found] ` <363801FFD7B74240A329CEC3F7FE4CC4030964F6@ntxboimbx07.micro n.com>
2004-11-19 1:02 ` Eljay Love-Jensen
2004-11-19 10:55 Pradip Singh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).