|
What is your requirement, If you want to hide the details of Object creation,
Refer Factory, builder, .. patterns(Design Patterns)
Contructors are required to identify the class whose object is created. Making it virtual is meaning less.
Best Regards
Raj
|
|
|
|
|
It depends on what you mean. It's true that C++ doesn't support virtual constructors per se, but there is a design pattern called the virtual constructor idiom[^] which may be what the you're after. Many programmers and designers use the term "virtual constructor" to refer to this idiom and are not talking about literally making constructors virtual.
Steve
|
|
|
|
|
|
A constant variable is one that can't be changed (at least the compiler won't let you do it
directly).
In-class means it is a member of a class.
For usage, the section "How do I define an in-class constant?" in Bjarne Stroustrup's
C++ Style and Technique FAQ[^] may help
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
why is v[i] = i++; and f(v[i],i++); deemed inappropiate in C++
|
|
|
|
|
A bit cryptic, maybe confusing, that's all (I dont' deem the above inappropiate).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
It's something which has been proposed by Stroustup. Basically it is involvind some kind of two reads in a single operation. Any furtehr light. How to identidy such situation. will a[j] = i++ be appropriate?
|
|
|
|
|
tom groezer wrote: will a[j] = i++ be appropriate?
yes, because the variable you use as an index, is not being modified on the same line of code. i++ means, return i, then increment it. a[j] will definately contain the old value of i. The thing is that when i is incremented is not clear. Does a[i] = i++ set the a at the index equal to the old i, or the new i ? It may be defined ( I don't think it is, I think it's compiler specific ), but it's at least hard to read.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: I don't think it is, I think it's compiler specific
AFAIK the postfix increment operator acts the following way:
use the current value of the variable in the statement and then increment it.
Christian Graus wrote: but it's at least hard to read.
I completely agree on the above.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: Christian Graus wrote: I don't think it is, I think it's compiler specific
AFAIK the postfix increment operator acts the following way:
use the current value of the variable in the statement and then increment it.
This is absolutely correct and of course considered C/C++ basics.
I think Christian meant that the statement
a[i] = i++; is an undefined behavior and the resulting operation is compiler specific.
It's undefined what index of a will be operated on.
If i equals 1 before the statement above, will a[1] be assigned 1 or will a[2] be assigned 1?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
IMHO should be always
a[1] = 1;
because a[i] = i++; is one statement.
What do you think about?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: IMHO should be always
a[1] = 1; because a[i] = i++; is one statement.
What do you think about?
Well, I can agree on that in this context.
However, this can get very complex for the compiler. i++ is a statement that is parsed by the compiler and would generate almost the same instructions if the statement isn't too complex. Consider the following "complier complex" code:
a[i] = foo( i++ ); I would be surprised if the compiler assigned the array index matching i before the incrementation. It will usually put the variable on the stack prior to the function call and then increment it using the incremented i as array index when assigning. This is also how the VC6 compiler resolves the statement.
But...
the VC6 compiler will assign 1 to a[1] with the following statements:
i = 1;
a[i] = i++; This is a simpler statement and then the compiler gets smart, but it doesn't work the same way as in the example above, i.e. if the function call is replaced by simply incrementing the variable it won't assign the same array index. And this is for the same compiler.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: a[i] = foo( i++ );
Actually the VC6 compiler is honestly doing its job, because
foo( i++ ); is by itself a statement.
Anyway I agree on the overall point of view and I will never encourage somebody to write code like that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I am a new learner of VC++ and usually get good support from code project.
I am facing problem with Streams. I need some kind guidance of some senior programmer.
Problem is that I receive some data in a ISpStreamFormat object. I want to read this data into byte pointers but when I call IStream->Read() functions with a non-zero argument as desired no of bytes to read, read method fails returning STG_E_INVALIDPOINTER message. Only fixing a zero "0" as the desired number of byted does not result in Failure message but it reads nothing.
So please if anybody guids me how to read binary data from ISpStreamFormat stream.
Regrads
Zia
|
|
|
|
|
smzhaq wrote: ISpStreamFormat
Never heard of it. What sort of data are you reading ? Why are the standard C++ streams not sufficient to the task ?
It sounds to me like your stream does not have a proper input source.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
thanx buddy
I was doing a blunder. In fact I was passing an uninitiallized pointer to the stream read function which was resulting in a bug.
Problem has been solved now. Thanx a lot
Regards
|
|
|
|
|
Hi, I'm using GetNamedSecurityInfo in a program I wrote to remove some registry keys from the Windows XP registry.
It seems to work on all the keys except for one. For some reason on one key it returns "The parameter is incorrect" as its error, yet I attempt to find this same key a moment later using the same path in a different function and it says that the key is valid.
Does anyone know what this "parameter is incorrect" might mean, besides it just having an invalid path name? All I'm passing it is a path, a pointer to an ACL to fill, and a pointer to a security descriptor.
Here's the code:
void RemoveAccessDenied(LPTSTR FullKey)<br />
{<br />
PSECURITY_DESCRIPTOR pSD = NULL;<br />
PACL pACL = NULL;<br />
<br />
GetNamedSecurityInfo(FullKey, SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION, NULL, NULL, &pACL, NULL, &pSD);<br />
<br />
}
Thanks!
KR
|
|
|
|
|
Found it; spybot was denying the registry change based on my blacklist.
KR
|
|
|
|
|
BAD Spybot BAD! *swat*
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi,
I used to code in C++ but stopped for about a year, anyway I am back but have ran into a problem on my first project:
Any solution I now create doesn't work, when I try and build it it builds fine, but when I try and run it, I get the error that:
"Unable to start program "C:\\...projects\test\debug\test.exe". The system could not find the file specified"
I realise this means that it hasn't created the debug information, but it hasn't created the release information either.
Also I can Build Solution, and it says it is fine, but the Compile option is greyed-out and I don't know what to do.
Is there an option in MVC++EE when you can turn off compiling it until you do something?
Any suggestions?
Thanks,
Any reply is appreciated.
-- modified at 8:47 Monday 11th June, 2007
|
|
|
|
|
Blekk wrote: I realise this means that it hasn't created the debug information
No, it means it can't create the program - your compile is failing due to some other error.
Blekk wrote: Is there an option in MVC++EE when you can turn off compiling it until you do something?
No, there shouldn't be. If it doesn't show the option, it probably doesn't think the option is valid, for some reason.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Ok thanks but I even just tried compiling this in a new solution and it didn't work:
#include <iostream>
using namespace std;
int main()
{
cout<<"This should work...";
return 0;
}
Any ideas?
|
|
|
|
|
I have a application in which I have to read a text file with more than 1 hundred thousand lines. I am having trouble with reading file and replacing the text in file. I want to read file's content and display it in Rich text edit quickly, and when I replace some text by other texts, the process must do quickly. I have tried using Notepad to read and replace some text, but it takes about 10 to 15 minutes to finish the works
duc an
|
|
|
|
|
|
hi all
please .. Can i print the output of program to the printer directly
please tell me
thank's all
<br />
#include <iostream.h><br />
<br />
main ()<br />
{<br />
cout <<"Hi all .. That's Me";<br />
<br />
return 0;<br />
}<br />
<br />
-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*
|
|
|
|