For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > Help!!! I give up...Confused!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help!!! I give up...Confused!
Robby

2006-05-24, 7:10 pm

Hello,

It is against my will to post such a lenghty problem, however... I give
up!....I don't know what is wrong with this program... It must have something
to do with the way my objects are declared which renders my base class to
forget the value of one of its members.

I recently got back into, inheritance, polymorphism and virtual methods. I
really don't need the power of polymorphism right now since I don't need to
create a base class pointer type. I just need to call methods in my classes
while in WndProc!
The program compiles without errors!

Anyhow, I think you would better understand the code posted below....
Again, sorry for the lenghty code... I have tried to cut it down the most I
can while keeping the integrity of the problem as a whole.


========================================
=============class components
{
public:
components(){}
virtual ~components() {}
virtual void SYS_set_FLAG_AllTrueInCase();
virtual bool SYS_get_FLAG_AllTrueInCase();
virtual void SYS_SFCC(bool bCondTrue);
private:

//By default this member is set to true before every "switch(message)"
bool FLAG_AllTrueInCase;
};


void components::SYS_set_FLAG_AllTrueInCase()

{
FLAG_AllTrueInCase =true;
}


bool components::SYS_get_FLAG_AllTrueInCase()

{
//Under cursor in debug, at this point, FLAG_AllTrueInCase
//is true??? Didn't we set it to false ???????
return FLAG_AllTrueInCase;
}


void components::SYS_SFCC(bool bCondTrue)
{

//Set FLAG_AllTrueInCase to true if FLAG_AllTrueInCase
//and bCondTrue equals to true else set it to false.

if(FLAG_AllTrueInCase && bCondTrue)
FLAG_AllTrueInCase =true;
else
FLAG_AllTrueInCase =false; //Therefore: FLAG_AllTrueInCase is set to
false...right!

}


//-----------------------------------------------



class transitions:public components
{
public:
transitions(){}
virtual ~transitions(){}
virtual bool SYS_get_FLAG_AllTrueInCase();
virtual void SYS_SFCC(bool bCondTrue);

};


bool transitions::SYS_get_FLAG_AllTrueInCase(
)
{
if (components::SYS_get_FLAG_AllTrueInCase(
))
return true;
else
return false;
}


void transitions::SYS_SFCC(bool bCondTrue)
{
components::SYS_SFCC(bCondTrue);
}


//-----------------------------------------------


class T_LOGIC:public transitions
{
public:
T_LOGIC(){}
virtual ~T_LOGIC(){}
virtual void get_BOOL_AND_INPUT (int Bool_ID_1, int Bool_ID_2, IO *io);
protected:
};

void T_LOGIC::get_BOOL_AND_INPUT(int Bool_ID_1, int Bool_ID_2, IO *io)
{

//Gets the actual value of input 1 and 2. If they are both true! then...
else....
//As I run the program, input 1 and 2 are false!!!!! so then (else is
fetched!)

if (io->getBOOL_INPUT_IMT(Bool_ID_1) && io->getBOOL_INPUT_IMT(Bool_ID_2))
transitions::SYS_SFCC(true);
else
transitions::SYS_SFCC(false);
}


//-----------------------------------------------


LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{

static ENVIR envir;
static IO io;

transitions *pT_TRANSITION = new transitions;
T_LOGIC *pT_LOGIC = new T_LOGIC;

switch(message)
{

case WM_TIMER:

//Upon the next line, the component's member
//FLAG_AllTrueInCase will be set to false!
pT_LOGIC->get_BOOL_AND_INPUT(2,3,&io);


//Now lets check for the value of FLAG_AllTrueInCase
//It Should return a false!!!! But it returns a true... !
if(pT_TRANSITION->SYS_get_FLAG_AllTrueInCase())
{}

.....other code.....

delete pT_TRANSITION;
delete pT_LOGIC;

....other code.....

========================================
=============

In short... What must I do to keep the component's member value as static. I
tried to make it static, but the compiler gives an error!

All suggestions very appreciated....

I feel very bad for this and above all, !

Hope to hear from you all!

--
Kind regards
Robert
David Wilkinson

2006-05-24, 7:10 pm

Robby wrote:

> Hello,
>
> It is against my will to post such a lenghty problem, however... I give
> up!....I don't know what is wrong with this program... It must have something
> to do with the way my objects are declared which renders my base class to
> forget the value of one of its members.
>
> I recently got back into, inheritance, polymorphism and virtual methods. I
> really don't need the power of polymorphism right now since I don't need to
> create a base class pointer type. I just need to call methods in my classes
> while in WndProc!
> The program compiles without errors!
>
> Anyhow, I think you would better understand the code posted below....
> Again, sorry for the lenghty code... I have tried to cut it down the most I
> can while keeping the integrity of the problem as a whole.
>
>
> ========================================
=============class components
> {
> public:
> components(){}
> virtual ~components() {}
> virtual void SYS_set_FLAG_AllTrueInCase();
> virtual bool SYS_get_FLAG_AllTrueInCase();
> virtual void SYS_SFCC(bool bCondTrue);
> private:
>
> //By default this member is set to true before every "switch(message)"
> bool FLAG_AllTrueInCase;
> };
>
>
> void components::SYS_set_FLAG_AllTrueInCase()

> {
> FLAG_AllTrueInCase =true;
> }
>
>
> bool components::SYS_get_FLAG_AllTrueInCase()

> {
> //Under cursor in debug, at this point, FLAG_AllTrueInCase
> //is true??? Didn't we set it to false ???????
> return FLAG_AllTrueInCase;
> }
>
>
> void components::SYS_SFCC(bool bCondTrue)
> {
>
> //Set FLAG_AllTrueInCase to true if FLAG_AllTrueInCase
> //and bCondTrue equals to true else set it to false.
>
> if(FLAG_AllTrueInCase && bCondTrue)
> FLAG_AllTrueInCase =true;
> else
> FLAG_AllTrueInCase =false; //Therefore: FLAG_AllTrueInCase is set to
> false...right!
>
> }
>
>
> //-----------------------------------------------
>
>
>
> class transitions:public components
> {
> public:
> transitions(){}
> virtual ~transitions(){}
> virtual bool SYS_get_FLAG_AllTrueInCase();
> virtual void SYS_SFCC(bool bCondTrue);
>
> };
>
>
> bool transitions::SYS_get_FLAG_AllTrueInCase(
)
> {
> if (components::SYS_get_FLAG_AllTrueInCase(
))
> return true;
> else
> return false;
> }
>
>
> void transitions::SYS_SFCC(bool bCondTrue)
> {
> components::SYS_SFCC(bCondTrue);
> }
>
>
> //-----------------------------------------------
>
>
> class T_LOGIC:public transitions
> {
> public:
> T_LOGIC(){}
> virtual ~T_LOGIC(){}
> virtual void get_BOOL_AND_INPUT (int Bool_ID_1, int Bool_ID_2, IO *io);
> protected:
> };
>
> void T_LOGIC::get_BOOL_AND_INPUT(int Bool_ID_1, int Bool_ID_2, IO *io)
> {
>
> //Gets the actual value of input 1 and 2. If they are both true! then...
> else....
> //As I run the program, input 1 and 2 are false!!!!! so then (else is
> fetched!)
>
> if (io->getBOOL_INPUT_IMT(Bool_ID_1) && io->getBOOL_INPUT_IMT(Bool_ID_2))
> transitions::SYS_SFCC(true);
> else
> transitions::SYS_SFCC(false);
> }
>
>
> //-----------------------------------------------
>
>
> LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
> WPARAM wParam, LPARAM lParam)
> {
>
> static ENVIR envir;
> static IO io;
>
> transitions *pT_TRANSITION = new transitions;
> T_LOGIC *pT_LOGIC = new T_LOGIC;
>
> switch(message)
> {
>
> case WM_TIMER:
>
> //Upon the next line, the component's member
> //FLAG_AllTrueInCase will be set to false!
> pT_LOGIC->get_BOOL_AND_INPUT(2,3,&io);
>
>
> //Now lets check for the value of FLAG_AllTrueInCase
> //It Should return a false!!!! But it returns a true... !
> if(pT_TRANSITION->SYS_get_FLAG_AllTrueInCase())
> {}
>
> ....other code.....
>
> delete pT_TRANSITION;
> delete pT_LOGIC;
>
> ...other code.....
>
> ========================================
=============
>
> In short... What must I do to keep the component's member value as static. I
> tried to make it static, but the compiler gives an error!
>
> All suggestions very appreciated....
>
> I feel very bad for this and above all, !
>
> Hope to hear from you all!



Robby:

1. You have a non-static member variable FLAG_AllTrueInCase that is not
initialized in the constructor. This is an absolute no-no. Thw whole
purpose of the cosntructor is to initialize the object.

2. I'm not sure what you mean by "keep the component's member value as
static". If you want it to be a static member, then learn how to define
a static member variable of a class (don't just give up). Hint: you have
to define it in the implementation file.

3. Your pT_TRANSITION and pT_LOGIC are pointers to separate objects, so
they have separate values of FLAG_AllTrueInCase.

4. Don't use "new" for local variables. Create them on the stack.

5. Use const modifier on methods that do not change the object (e.g.
your SYS_get_FLAG_AllTrueInCase(). It makes the code so much easier to
understand.

David Wilkinson
Steve Alpert

2006-05-24, 7:10 pm

I'll not read through your entire posting but simply let you know what I did to
solve this kind of problem. I needed to call class instance methods from within
a windproc associated with various windows. I simply created a property for the
window and stored a pointer to my class. The window could access the property
and call the methods via pC->method(...)

/steveA

Robby wrote:
> Hello,
>
> It is against my will to post such a lenghty problem, however... I give
> up!....I don't know what is wrong with this program... It must have something
> to do with the way my objects are declared which renders my base class to
> forget the value of one of its members.
>
> I recently got back into, inheritance, polymorphism and virtual methods. I
> really don't need the power of polymorphism right now since I don't need to
> create a base class pointer type. I just need to call methods in my classes
> while in WndProc!
> The program compiles without errors!
>
> Anyhow, I think you would better understand the code posted below....
> Again, sorry for the lenghty code... I have tried to cut it down the most I
> can while keeping the integrity of the problem as a whole.
>
>
> ========================================
=============class components
> {
> public:
> components(){}
> virtual ~components() {}
> virtual void SYS_set_FLAG_AllTrueInCase();
> virtual bool SYS_get_FLAG_AllTrueInCase();
> virtual void SYS_SFCC(bool bCondTrue);
> private:
>
> //By default this member is set to true before every "switch(message)"
> bool FLAG_AllTrueInCase;
> };
>
>
> void components::SYS_set_FLAG_AllTrueInCase()

> {
> FLAG_AllTrueInCase =true;
> }
>
>
> bool components::SYS_get_FLAG_AllTrueInCase()

> {
> //Under cursor in debug, at this point, FLAG_AllTrueInCase
> //is true??? Didn't we set it to false ???????
> return FLAG_AllTrueInCase;
> }
>
>
> void components::SYS_SFCC(bool bCondTrue)
> {
>
> //Set FLAG_AllTrueInCase to true if FLAG_AllTrueInCase
> //and bCondTrue equals to true else set it to false.
>
> if(FLAG_AllTrueInCase && bCondTrue)
> FLAG_AllTrueInCase =true;
> else
> FLAG_AllTrueInCase =false; //Therefore: FLAG_AllTrueInCase is set to
> false...right!
>
> }
>
>
> //-----------------------------------------------
>
>
>
> class transitions:public components
> {
> public:
> transitions(){}
> virtual ~transitions(){}
> virtual bool SYS_get_FLAG_AllTrueInCase();
> virtual void SYS_SFCC(bool bCondTrue);
>
> };
>
>
> bool transitions::SYS_get_FLAG_AllTrueInCase(
)
> {
> if (components::SYS_get_FLAG_AllTrueInCase(
))
> return true;
> else
> return false;
> }
>
>
> void transitions::SYS_SFCC(bool bCondTrue)
> {
> components::SYS_SFCC(bCondTrue);
> }
>
>
> //-----------------------------------------------
>
>
> class T_LOGIC:public transitions
> {
> public:
> T_LOGIC(){}
> virtual ~T_LOGIC(){}
> virtual void get_BOOL_AND_INPUT (int Bool_ID_1, int Bool_ID_2, IO *io);
> protected:
> };
>
> void T_LOGIC::get_BOOL_AND_INPUT(int Bool_ID_1, int Bool_ID_2, IO *io)
> {
>
> //Gets the actual value of input 1 and 2. If they are both true! then...
> else....
> //As I run the program, input 1 and 2 are false!!!!! so then (else is
> fetched!)
>
> if (io->getBOOL_INPUT_IMT(Bool_ID_1) && io->getBOOL_INPUT_IMT(Bool_ID_2))
> transitions::SYS_SFCC(true);
> else
> transitions::SYS_SFCC(false);
> }
>
>
> //-----------------------------------------------
>
>
> LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
> WPARAM wParam, LPARAM lParam)
> {
>
> static ENVIR envir;
> static IO io;
>
> transitions *pT_TRANSITION = new transitions;
> T_LOGIC *pT_LOGIC = new T_LOGIC;
>
> switch(message)
> {
>
> case WM_TIMER:
>
> //Upon the next line, the component's member
> //FLAG_AllTrueInCase will be set to false!
> pT_LOGIC->get_BOOL_AND_INPUT(2,3,&io);
>
>
> //Now lets check for the value of FLAG_AllTrueInCase
> //It Should return a false!!!! But it returns a true... !
> if(pT_TRANSITION->SYS_get_FLAG_AllTrueInCase())
> {}
>
> ....other code.....
>
> delete pT_TRANSITION;
> delete pT_LOGIC;
>
> ...other code.....
>
> ========================================
=============
>
> In short... What must I do to keep the component's member value as static. I
> tried to make it static, but the compiler gives an error!
>
> All suggestions very appreciated....
>
> I feel very bad for this and above all, !
>
> Hope to hear from you all!
>



--
Steve Alpert
my email fgrir.nycreg @ tr.pbz is encrypted with ROT13 (www.rot13.org) and spaces

Tamas Demjen

2006-05-24, 7:10 pm

Robby wrote:

> {
> public:
> components(){}
> virtual ~components() {}
> virtual void SYS_set_FLAG_AllTrueInCase();
> virtual bool SYS_get_FLAG_AllTrueInCase();
> virtual void SYS_SFCC(bool bCondTrue);
> private:
>
> //By default this member is set to true before every "switch(message)"
> bool FLAG_AllTrueInCase;
> };


To start with, you must initialize your member variables in the
constructor. By default, all members contain completely random values.
You must set FLAG_AllTrueInCase to either true or false in the
constructor, or else its initial value will be random.

> In short... What must I do to keep the component's member value as static. I
> tried to make it static, but the compiler gives an error!


You create and destroy your class every time. That's why it forgets its
previous value. How about making one instance of the object, which is
not destroyed but reused between function calls? When an object goes out
of scope, of course its member variables get lost. You only destroy an
object when you no longer need it.

Yes, you can declare members static, in which case all instances of the
same object will share the same value. It seems that's not what you want.

Tom
Robby

2006-05-27, 7:05 pm

Hi David,

First and foremost, before I begin exchanging with you about our VC++
postings, I would like to confirm with you that this reply post works! For
as you know I have been having problems responding to my messages when going
through the MS website. And now, I am trying to reply to you through the
Microsoft Outlook newsreader. (I fiddled around with Outlook and now I am
trying this in Outlook, I know that I should of used Outlook express! sorry,
my mistake!.... However I would like to test this!) I have created a new
newsgroup account and subscribed to it.... it is the first time I do this,
so I don't know if I did this right!

Would you be so kind to let me know if you get this test reply post, I would
truely appreciate your cooperation on this!

Thankyou my freind!

Robert!

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:OMYT%23G1fGHA.1276@TK2MSFTNGP03.phx.gbl...
> Robby wrote:
>
>
>
> Robby:
>
> 1. You have a non-static member variable FLAG_AllTrueInCase that is not
> initialized in the constructor. This is an absolute no-no. Thw whole
> purpose of the cosntructor is to initialize the object.
>
> 2. I'm not sure what you mean by "keep the component's member value as
> static". If you want it to be a static member, then learn how to define a
> static member variable of a class (don't just give up). Hint: you have to
> define it in the implementation file.
>
> 3. Your pT_TRANSITION and pT_LOGIC are pointers to separate objects, so
> they have separate values of FLAG_AllTrueInCase.
>
> 4. Don't use "new" for local variables. Create them on the stack.
>
> 5. Use const modifier on methods that do not change the object (e.g. your
> SYS_get_FLAG_AllTrueInCase(). It makes the code so much easier to
> understand.
>
> David Wilkinson



David Wilkinson

2006-05-31, 7:15 pm

Robby wrote:

> Hi David,
>
> First and foremost, before I begin exchanging with you about our VC++
> postings, I would like to confirm with you that this reply post works! For
> as you know I have been having problems responding to my messages when going
> through the MS website. And now, I am trying to reply to you through the
> Microsoft Outlook newsreader. (I fiddled around with Outlook and now I am
> trying this in Outlook, I know that I should of used Outlook express! sorry,
> my mistake!.... However I would like to test this!) I have created a new
> newsgroup account and subscribed to it.... it is the first time I do this,
> so I don't know if I did this right!
>
> Would you be so kind to let me know if you get this test reply post, I would
> truely appreciate your cooperation on this!


Robby:

I didn't see this before. But it worked! I never use Outlook or Outlook
Express, but I would think that you can use either as a newsreader. I
use Mozilla mail, which works OK but has few quirks (maybe fixed now, I
am not using the latest version).

David Wilkinson
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com