I put everything in one file for ease of use; also I have #include
<*.hfiles instead of the <*since my compiler is pre-ANSI C so it
needs the .h
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
class Cmd {
public:
virtual ~Cmd() {}
char* printCmd()
{
return _name;
}
protected:
Cmd() {}
char _name[16];
};
class ACmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new ACmd;
}
return _instance;
}
~ACmd() {}
private:
ACmd()
{
strcpy(_name, "ACmd");
}
static Cmd* _instance;
};
class BCmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new BCmd;
}
return _instance;
}
~BCmd() {}
private:
BCmd()
{
strcpy(_name, "ACmd");
}
static Cmd* _instance;
};
typedef struct {
Cmd* cmd;
} CmdS;
Cmd* ACmd::_instance =NULL;
Cmd* BCmd::_instance =NULL;
int main()
{
Cmd* cmd=ACmd::getIn stance();
Cmd* cmd1=BCmd::getI nstance();
CmdS* cmds=(CmdS*)mal loc(sizeof(CmdS ));
CmdS* cmds1=(CmdS*)ma lloc(sizeof(Cmd S));
cmds->cmd=cmd;
cmds1->cmd=cmd1;
cout << "cmds->cmd: " << cmds->cmd->printCmd()
<< hex << " 0x" << cmds->cmd
<< " ,cmds1->cmd: " << cmds1->cmd->printCmd()
<< " 0x" << cmds1->cmd << endl;
// Uncomment one or the other assignment below...
// This satisfies the if statement below;
// however, the value AND contents of cmds->cmd are
// overwritten
cmds->cmd=cmds1->cmd;
// This does NOT satisfy the if statement below;
// however, the value cmds->cmd are preserved,
// only its contents change
// *cmds->cmd=*cmds1->cmd;
cout << "cmds->cmd: " << cmds->cmd->printCmd()
<< hex << " 0x" << cmds->cmd
<< " ,cmds1->cmd: " << cmds1->cmd->printCmd()
<< " 0x" << cmds1->cmd << endl;
if (cmds->cmd==BCmd::get Instance()) {
cout << "equal" << endl;
}
return 0;
}
Using the first assignment yields; notice how the both value and
content of cmds->cmd changed
cmds->cmd: ACmd 0x0x996e008 ,cmds1->cmd: ACmd 0x0x996e020
cmds->cmd: ACmd 0x0x996e020 ,cmds1->cmd: ACmd 0x0x996e020
equal
Using the second assignment yields; here notice how the value of
cmds->cmd did NOT change, only the content; however the if statement
failed.
cmds->cmd: ACmd 0x0x8c7b008 ,cmds1->cmd: ACmd 0x0x8c7b020
cmds->cmd: ACmd 0x0x8c7b008 ,cmds1->cmd: ACmd 0x0x8c7b020
How can I get this?
cmds->cmd: ACmd 0x0x8c7b008 ,cmds1->cmd: ACmd 0x0x8c7b020
cmds->cmd: ACmd 0x0x8c7b008 ,cmds1->cmd: ACmd 0x0x8c7b020
equal 12 1502
Zilla wrote:
I put everything in one file for ease of use; also I have #include
<*.hfiles instead of the <*since my compiler is pre-ANSI C so it
needs the .h
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
class Cmd {
public:
virtual ~Cmd() {}
char* printCmd()
{
return _name;
}
protected:
Cmd() {}
char _name[16];
};
class ACmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new ACmd;
}
return _instance;
}
~ACmd() {}
private:
ACmd()
{
strcpy(_name, "ACmd");
}
static Cmd* _instance;
};
class BCmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new BCmd;
}
return _instance;
}
~BCmd() {}
private:
BCmd()
{
strcpy(_name, "ACmd");
I suspect your error lies here.
}
static Cmd* _instance;
};
typedef struct {
Cmd* cmd;
} CmdS;
On Oct 19, 5:02 pm, red floyd <no.s...@here.d udewrote:
Zilla wrote:
I put everything in one file for ease of use; also I have #include
<*.hfiles instead of the <*since my compiler is pre-ANSI C so it
needs the .h
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
class Cmd {
public:
virtual ~Cmd() {}
char* printCmd()
{
return _name;
}
protected:
Cmd() {}
char _name[16];
};
class ACmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new ACmd;
}
return _instance;
}
~ACmd() {}
private:
ACmd()
{
strcpy(_name, "ACmd");
}
static Cmd* _instance;
};
class BCmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new BCmd;
}
return _instance;
}
~BCmd() {}
private:
BCmd()
{
strcpy(_name, "ACmd");
I suspect your error lies here.
}
static Cmd* _instance;
};
typedef struct {
Cmd* cmd;
} CmdS;- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
How? ACmd and BCmd are singletons, and that's how one codes one. See
Design Patterns book.
Zilla wrote:
On Oct 19, 5:02 pm, red floyd <no.s...@here.d udewrote:
>Zilla wrote:
>>I put everything in one file for ease of use; also I have #include <*.hfiles instead of the <*since my compiler is pre-ANSI C so it needs the .h
>>#include <iostream.h> #include <iomanip.h> #include <string.h>
>>class Cmd { public: virtual ~Cmd() {} char* printCmd() { return _name; } protected: Cmd() {} char _name[16]; };
>>class ACmd : public Cmd { public: static Cmd* getInstance() { if (!_instance) { _instance=new ACmd; } return _instance; } ~ACmd() {} private: ACmd() { strcpy(_name, "ACmd"); } static Cmd* _instance; };
>>class BCmd : public Cmd { public: static Cmd* getInstance() { if (!_instance) { _instance=new BCmd; } return _instance; } ~BCmd() {} private: BCmd() { strcpy(_name, "ACmd");
I suspect your error lies here.
>> } static Cmd* _instance; };
>>typedef struct { Cmd* cmd; } CmdS;- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
How? ACmd and BCmd are singletons, and that's how one codes one. See
Design Patterns book.
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Zilla wrote:
On Oct 19, 5:02 pm, red floyd <no.s...@here.d udewrote:
>Zilla wrote:
>>I put everything in one file for ease of use; also I have #include <*.hfiles instead of the <*since my compiler is pre-ANSI C so it needs the .h
>>#include <iostream.h> #include <iomanip.h> #include <string.h>
>>class Cmd { public: virtual ~Cmd() {} char* printCmd() { return _name; } protected: Cmd() {} char _name[16]; };
>>class ACmd : public Cmd { public: static Cmd* getInstance() { if (!_instance) { _instance=new ACmd; } return _instance; } ~ACmd() {} private: ACmd() { strcpy(_name, "ACmd"); } static Cmd* _instance; };
>>class BCmd : public Cmd { public: static Cmd* getInstance() { if (!_instance) { _instance=new BCmd; } return _instance; } ~BCmd() {} private: BCmd() { strcpy(_name, "ACmd");
I suspect your error lies here.
>> } static Cmd* _instance; };
>>typedef struct { Cmd* cmd; } CmdS;- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
How? ACmd and BCmd are singletons, and that's how one codes one. See
Design Patterns book.
You're thinking so much outside the box that you aren't seeing the
obvious mistake. Hint: it's a copy-and-paste error. Look at it again
and this time really try to see what the function is and what it needs
to do (what every statement needs to do), and what it actually does
(and what the effect of it is).
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Oct 19, 6:01 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Zilla wrote:
On Oct 19, 5:02 pm, red floyd <no.s...@here.d udewrote:
Zilla wrote: I put everything in one file for ease of use; also I have #include <*.hfiles instead of the <*since my compiler is pre-ANSI C so it needs the .h
>#include <iostream.h> #include <iomanip.h> #include <string.h>
>class Cmd { public: virtual ~Cmd() {} char* printCmd() { return _name; } protected: Cmd() {} char _name[16]; };
>class ACmd : public Cmd { public: static Cmd* getInstance() { if (!_instance) { _instance=new ACmd; } return _instance; } ~ACmd() {} private: ACmd() { strcpy(_name, "ACmd"); } static Cmd* _instance; };
>class BCmd : public Cmd { public: static Cmd* getInstance() { if (!_instance) { _instance=new BCmd; } return _instance; } ~BCmd() {} private: BCmd() { strcpy(_name, "ACmd");
I suspect your error lies here.
> } static Cmd* _instance; };
>typedef struct { Cmd* cmd; } CmdS;- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
How? ACmd and BCmd are singletons, and that's how one codes one. See
Design Patterns book.
You're thinking so much outside the box that you aren't seeing the
obvious mistake. Hint: it's a copy-and-paste error. Look at it again
and this time really try to see what the function is and what it needs
to do (what every statement needs to do), and what it actually does
(and what the effect of it is).
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text -
- Show quoted text -
Ah, the _name value, but that's beside the point - I don't care what
the names are - make them same. Look at the pointer values that I
print out. TY
On Oct 19, 6:10 pm, Zilla <zill...@bellso uth.netwrote:
On Oct 19, 6:01 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Zilla wrote:
On Oct 19, 5:02 pm, red floyd <no.s...@here.d udewrote:
>Zilla wrote:
>>I put everything in one file for ease of use; also I have #include
>><*.hfiles instead of the <*since my compiler is pre-ANSI C so it
>>needs the .h
>>#include <iostream.h>
>>#include <iomanip.h>
>>#include <string.h>
>>class Cmd {
>>public:
>> virtual ~Cmd() {}
>> char* printCmd()
>> {
>> return _name;
>> }
>>protected:
>> Cmd() {}
>> char _name[16];
>>};
>>class ACmd : public Cmd {
>>public:
>> static Cmd* getInstance()
>> {
>> if (!_instance) {
>> _instance=new ACmd;
>> }
>> return _instance;
>> }
>> ~ACmd() {}
>>private:
>> ACmd()
>> {
>> strcpy(_name, "ACmd");
>> }
>> static Cmd* _instance;
>>};
>>class BCmd : public Cmd {
>>public:
>> static Cmd* getInstance()
>> {
>> if (!_instance) {
>> _instance=new BCmd;
>> }
>> return _instance;
>> }
>> ~BCmd() {}
>>private:
>> BCmd()
>> {
>> strcpy(_name, "ACmd");
>I suspect your error lies here.
>> }
>> static Cmd* _instance;
>>};
>>typedef struct {
>> Cmd* cmd;
>>} CmdS;- Hide quoted text -
>- Show quoted text -- Hide quoted text -
>- Show quoted text -
How? ACmd and BCmd are singletons, and that's how one codes one. See
Design Patterns book.
You're thinking so much outside the box that you aren't seeing the
obvious mistake. Hint: it's a copy-and-paste error. Look at it again
and this time really try to see what the function is and what it needs
to do (what every statement needs to do), and what it actually does
(and what the effect of it is).
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text -
- Show quoted text -
Ah, the _name value, but that's beside the point - I don't care what
the names are - make them same. Look at the pointer values that I
print out. TY- Hide quoted text -
- Show quoted text -
Ok here's output for correcte _name cut & paste error
With cmds->cmd=cmds1->cmd; uncommented...
cmds->cmd: ACmd 0x0x40004820 ,cmds1->cmd: BCmd 0x0x40004840
cmds->cmd: BCmd 0x0x40004840 ,cmds1->cmd: BCmd 0x0x40004840
equal
With *cmds->cmd=*cmds1->cmd; uncommented
cmds->cmd: ACmd 0x0x40004820 ,cmds1->cmd: BCmd 0x0x40004840
cmds->cmd: BCmd 0x0x40004820 ,cmds1->cmd: BCmd 0x0x40004840
Again, in the first case, value AND content of cmds->cmd changed, but
if passed. In the seconde case, ONLY content changed, bugt if fails.
I want ONLY content change, and passing if. TY again.
Zilla wrote:
On Oct 19, 6:10 pm, Zilla <zill...@bellso uth.netwrote:
>On Oct 19, 6:01 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Again, in the first case, value AND content of cmds->cmd changed, but
if passed. In the seconde case, ONLY content changed, bugt if fails.
I want ONLY content change, and passing if. TY again.
OK, I misunderstood. I figured you were looking at the output and
seeing ACmd multiple times and getting confuse.
Zilla wrote:
On Oct 19, 6:10 pm, Zilla <zill...@bellso uth.netwrote:
>On Oct 19, 6:01 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>>Zilla wrote: On Oct 19, 5:02 pm, red floyd <no.s...@here.d udewrote: Zilla wrote: >I put everything in one file for ease of use; also I have #include ><*.hfile s instead of the <*since my compiler is pre-ANSI C so it >needs the .h
[redacted]
>
Again, in the first case, value AND content of cmds->cmd changed, but
if passed. In the seconde case, ONLY content changed, bugt if fails.
I want ONLY content change, and passing if. TY again.
It could be a compiler bug, especially since your compiler is apparently
ancient (by your own admission).
On Oct 19, 6:59 pm, red floyd <no.s...@here.d udewrote:
Zilla wrote:
On Oct 19, 6:10 pm, Zilla <zill...@bellso uth.netwrote:
On Oct 19, 6:01 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>Zilla wrote: On Oct 19, 5:02 pm, red floyd <no.s...@here.d udewrote: Zilla wrote: I put everything in one file for ease of use; also I have #include <*.hfiles instead of the <*since my compiler is pre-ANSI C so it needs the .h
[redacted]
Again, in the first case, value AND content of cmds->cmd changed, but
if passed. In the seconde case, ONLY content changed, bugt if fails.
I want ONLY content change, and passing if. TY again.
It could be a compiler bug, especially since your compiler is apparently
ancient (by your own admission).
Thanks, but it's less fundamental than that since it happens in Visual
C++ 2005. I use HPUX 10.20 (for technical reasons) at work. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vinay Aggarwal |
last post by:
I have been thinking about the lazy initialization and double checked
locking problem. This problem is explain in detail here
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
I am not fully convinced that this problem cannot be
solved. I am going to propose a solution here. For the sake of
discussion I will post my solution here. It is possible that the
proposed solution does not work, feedback and comments are...
|
by: wooks |
last post by:
I have defined a schema with an xsd:choice element for 2 mutually
exclusive fields.
When both are present I get an error which is good, but what is not so
good is the error message which says something like "Element content
is invalid. Expecting: fieldname, {...."
The problem (if it is one) is that the "Expecting: fieldname..." bit
is wrong - fieldname is not the next field... in fact it's optional.
However it seems to have tagged...
|
by: softengine |
last post by:
Can and how do you alter a data view to include a look up field from another
data table? The data table of the dataview only has the key, the value I need
is in another data table.
Can and how to you reference the value of a column in a data table/view from
the row filter string of a different data view.
I'm using a strongly typed dataset.
Below is more info.
|
by: WertmanTheMad |
last post by:
Ive been playing with this for a few days and thought I might thow it
out for seggestions.
I have Several Queries that need counts returned
The Queries are Mutually Exclusive meaning whatever Query they return
in first they cannot be included in the counts of any queries below
them.
This set of queries for example
|
by: ScottAR |
last post by:
I'm writing simulator to help with testing out problems with deadlocking on a
database.
I have a function which I call from a delegate BeginInvoke call, and
depending on the simulation I might have from three to 20 threads running.
here's the function...
void DoTest()
{
for(int jj=0;jj<Y;jj++)
| |
by: js |
last post by:
I include a asp:RadioButton in an ItemTemplate of a DataGrid like the
following. However, the radio buttons are not mutual exclusive where
select one will deselect the rest of the radio buttons. I know there is
a similar bug with RadioButton in a DataList. Does this bug also apply
to Datagrid? If not, how can I set them to be selected mutually
exclusively?
<asp:datagrid id="MyDataGrid" runat="server" CssClass="InventoryTable">...
|
by: Stimp |
last post by:
I'm getting the error:
'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive
when I try to populate a series of dropdowns... any idea what I could be
doing wrong here?
Thanks.
--
|
by: Stimp |
last post by:
Hi all,
I've come back to this problem again and I've identified which part of
my code is producing the error:
"'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive"
I have a dropdown 'Year' and it contains a list of years from 2000 to
2005. This dropdown is populated on page load.
|
by: Dooman |
last post by:
Hello,
I am getting this error when binding a drop down list box to a
dataset:
The 'SelectedIndex' and 'SelectedValue' attributes are mutually
exclusive
I have looked at other posts and they al refer to this error when
accessing data in the list box.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |