|
Making the variable a class static does little to the design. It just changes the namespace. If it was bad code as a global variable, it is still bad code as a class static.
My question is why can't the vector be passed by address or reference to the global functions. Then you avoid the global variables, true or class statics.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
1. Filling the vector through the global or static pointer isn't a good idea. You should pass the vector to the MyOtherFunction by reference.
<br />
void CMyClass::MyOtherFunction(vector<CString>& vec)<br />
{<br />
vec.push_back(...)<br />
}<br />
2. If the compiler generates error on *g_pvecStrings = vecStrings , I think that your class CWBString is the deliquent (because with CString it works ok). The assignment operator in vector causes assignments of each element. Hence, did you declared correctly the copy constructor or assignment operator in CWBString ?
Robert-Antonio
"Science is a differerntial equation.
Religion is a boundary condition."
|
|
|
|
|
Thanks Robert for your reply!
Robert A. T. Káldy wrote:
1. Filling the vector through the global or static pointer isn't a good idea. You should pass the vector to the MyOtherFunction by reference.
I have been trying EXACTLY that now, but it is cribbing about xutility :
c:\program files\microsoft visual studio\vc98\include\xutility(39) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const class CWBString' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\vc98\include\vector(170) : see reference to function template instantiation 'void __cdecl std::fill(class CWBString *,class CWBString *,const class CWBString &)' being compiled
Robert A. T. Káldy wrote:
2. If the compiler generates error on *g_pvecStrings = vecStrings, I think that your class CWBString is the deliquent (because with CString it works ok). The assignment operator in vector causes assignments of each element. Hence, did you declared correctly the copy constructor or assignment operator in CWBString?
I am using CWBString extensively in my whole project and it has a (deep) copy constructor, as well as almost ALL the operators overloaded for standards as well as varied purposes (varied like *= for IsSimilar() in which I check for similar strings).
So I suppose my problem was that I was trying to use STL containers like normal pointers which can be shallow copied! I hope I'm correct here...
Thanks again!
Nirav
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Tim Smith wrote:
Making the variable a class static does little to the design. It just changes the namespace. If it was bad code as a global variable, it is still bad code as a class static.
I disagree. There are legitimate reasons to have class static variables and they are definitly not as bad as globals as you can make them private or protected. If the same data will be shared for all instances of an object it makes no sense to store a pointer to the data in each instance.
John
|
|
|
|
|
Hi guys,
is there any possibility to load a jpg or bmp with more than 256 colors in a dialog? i know how it works with a bmp witch has 256 colors.
Thanks in advance!
J.J.
|
|
|
|
|
the problem in this code is that it can't compile it when "A" is defined as "int"
"C:\Documents and Settings\simon\Desktop\the program.cpp(34) : error C2443: operand size conflict"
in my program A is in the range of 1-512 in decimal so thier is no problem with the size.
so how i force it to compile?
or how i change the program to compile it?
void light_port_b(int A)
{
_asm
{
mov Dx,PORTB
Mov Al,A
Out Dx,Al
}
}
thanks in advance
|
|
|
|
|
Register EAX = 4 bytes.
Register AX = 2 bytes.
Register AL = 1 byte.
void light_port_b(int A)
{
unsigned char t = (unsigned char) A;
// sizeof (int) = 4 (bytes).
// sizeof (unsigned char) = 1 (byte).
_asm
{
MOV DX, PORTB
MOV AL, t
OUT DX, AL
}
}
<b>Maxwell Chen</b>
|
|
|
|
|
thanks alot for the quick respond.
i have more questions (sorry if you think that they stupid).
1.as much as i know unsigned char is in the range of 0-255
so if i give him 256-512 it would work?
2. char is defined as a sign and i need numbers so when i write
"MOV AL, t" and int A=256 it moves the number 256 to or the sign of 256 to AL? (i need the number)
|
|
|
|
|
1) For such an expression:
unsigned char t = 257;
t is truncated. Thus, value of t will be 1 as a result.
2) I would suggest you try ...
unsigned short bbb = A;
_asm
{
MOV DX, PORTB
MOV AX, bbb
OUT DX, AX
}
<b>Maxwell Chen</b>
|
|
|
|
|
sorry it's in the range of 1-256
so if i will write "unsigned char t = (unsigned char) A;"
between 1-255 AL will get the same numbers.
and if i will give A,
the value 256, AL will get the number 0,and i would know it was 256.
I understood you correctly?
|
|
|
|
|
My only comment is unless you are in a device driver the Out Dx,Al will probably throw a hardware exception in NT, 2K, 2K3 or XP.
John
|
|
|
|
|
not only probably... it will!
Don't try it, just do it!
|
|
|
|
|
That's what I thought but I have ran some old dos games (in XP) with soundblaster and they worked. I was surprized of this. Do you know how this works?? Is it because of the VDM?
John
|
|
|
|
|
I create a signed message with CryptSignMessage, but I found this function would read the whole data to be signed into memory, if I want to sign a file which size is 100MB, I must malloc 100MB memory for it.
I need a solution that can sign message as a block by block.
|
|
|
|
|
what is the difference between assignment operator and copy constructor
thanx
|
|
|
|
|
class A
{
public:
A() {}
A(const A& t) { std::cout << "Copy ctor\n"; /* ... */ }
operator = (A& r) { std::cout << "Assignment ctor\n"; /* ... */ }
};
void f()
{
A aa;
A bb = aa; // Copy ctor is used.
A cc;
cc = aa; // Assignment ctor is used.
}
<b>Maxwell Chen</b>
|
|
|
|
|
thanx 4 replying maxwell
r u seen my question these think i know
thanx
|
|
|
|
|
In the book "The C++ Programming Language, 3rd Ed" by Stroustrup,
page 246,
The fundamental reason is that a copy constructor initializes uninitialized memory, whereas the copy assignment operator must correctly deal with a well-constructed object.
Maxwell Chen
|
|
|
|
|
Hi to all,
I made a Visual C++ MDI app with help support
Project name is *****Manager,and I set the builder
to build my app as *****Man.exe
My help file is *****Manager.hlp,but if I click
on the help button in my app It requested me
for *****Man.hlp
Who can I set my app to search for default for
*****Manager.hlp?
Thanks to all
Cristian
|
|
|
|
|
From the MSDN:
CWinApp::m_pszHelpFilePath
Remarks
Contains the path to the application’s Help file. By default, the framework initializes m_pszHelpFilePath to the name of the application with ".HLP" appended. To change the name of the help file, set m_pszHelpFilePath to point to a string that contains the complete name of the desired help file. A convenient place to do this is in the application's InitInstance function. m_pszHelpFilePath is a public variable of type const char*.
Note If you assign a value to m_pszHelpFilePath, it must be dynamically allocated on the heap. The CWinApp destructor calls free( ) with this pointer. You many want to use the _tcsdup( ) run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example:
//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszHelpFilePath);
//Change the name of the .HLP file.
//The CWinApp destructor will free the memory.
m_pszHelpFilePath=_tcsdup(_T(“d:\\somedir\\myhelp.hlp”));
CWinApp Overview | Class Members | Hierarchy Chart
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
Thanks very much
I first tried to search the solution in MSDN library but I didn't found anything,probably I was searching in the wrong direction
And like we say in Italy...
CIAO CIAO
|
|
|
|
|
Thats OK. Half the problem with the MSDN is you need to know half the key words just to get near the right topic. In this partivular case after reading your question, I knew exactly what to look for. :smug:
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
Hi!
The command, char* lltostr(long long value, char* endptr), are not defined in string?
How do I get it to work?
|
|
|
|
|
Not sure what it is your trying to do, you may have your wires crossed,
If you want to get a long value into a string format, you could do this:
long myLong = 1231213;
CString strLong;
strLong.Format("%d",myLong);
//strLong will then be "1231213"//////////////////////
or if the other way round...getting a long from a string
CString strLong = "1231213";
l = atol( s );
If you have to use a char[] and not a CString then do this, this is prob what you want to do.....
long myLong = 1231213;
sprintf( someChar, "%d",longvalue);
will give "1231213" in char[] named someChar
Is this what you mean???
Ross W
|
|
|
|
|
I have a COleDateTime object initialised in the following way.
COleDateTime m_ReadPointer = COleDateTime::GetCurrentTime();
I need to know a way to update the object to reflect the correct datetime given the TimeZone id. For eg. 1259
A Code snippet will be helpful
Dimple
|
|
|
|