|
Hi,
sharion wrote: If doesn't find, then enter base class---Super class to find it.
above explanation is correct?
- Here you are littlebit right, but virtual keyword doing magic here,
sharion wrote: when the compiler runs ref.someMethod();
Basically there is two type of binding
1. Run-time binding (or late binding)
- if same function define in parent class with same signature and it virtual, then compiler ignore it for run-time, and run time function will be called using VPTR and VPTABLE.
2. Compile-time binding (or erly binding)
- if above is not a case then compiler resolve binding at compile time only.
Parag Patel
Sr. Software Eng, Varaha Systems
|
|
|
|
|
sharion wrote: If the someMethod() in Sub class is
virtual void someMethod(int i = 1){cout<<"in Sub class"<<endl}
when the compiler runs ref.someMethod(); statement,what is the output?
In VS 2005,the output is "in Super class". I feel it is hard to understand,I believe the right result is "in Sub class".
No, the compiler is correct. In this case, there are two possible functions matching ref.someMethod() . The C++ Standard defines rules by which the compiler can decide which is the best match. These rules specify that a function with no parameters is a better match than a function with a parameter which has a default value. The fact that one of the methods is implemented in the derived class and one in the base class has no impact.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have a problem of number formatting
I made a function to convert from number to string.
and I used "stringstream" class for converting.
like this
string strText;
stringstream ssBuf;
ssBuf<<55555;
ssBuf>>strText;
I expect "55555" as result. but the result is "55,555".
How do I remove thousand seperator "," in string?
Thanks.
cozyu
modified on Wednesday, April 15, 2009 10:25 PM
|
|
|
|
|
Your locale[^] is getting in the way.
You need to tell the stringstream to use a locale without number punctuation. The simplest way to do that is to just use the std::locale::classic() locale like this:
std::string strText;
std::stringstream ssBuf;
ssBuf.imbue(std::locale::classic());
ssBuf<<55555;
ssBuf>>strText;
However, this loses any other locale-specific properties, so you might just want to use the number punctuation bit of the classic locale, like this:
std::string strText;
std::stringstream ssBuf;
std::locale l;
l = l.combine<std::numpunct<char> >(std::locale::classic());
ssBuf.imbue(l);
ssBuf<<55555;
ssBuf>>strText;
The combine method call copies your global locale and replaces the copy's number punctuation facet with the classic locale's number punctuation facet.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Great reply, got my 5
Don't you consider writing an article for CP ? I think you could bring really valuable things
|
|
|
|
|
Cedric Moonen wrote: Great reply, got my 5
Cheers
Cedric Moonen wrote: Don't you consider writing an article for CP ?
There are a few things I've got that I've thought about writing up. Trouble is, I'm lazy It's a good attribute for a developer, as it means you're more likely to use someone else's code than write your own, but not so great for article writing!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: Your locale[^] is getting in the way.
Mine is set to use commas, yet I see 55555 when using the OP's code snippet.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Yeah, so did I, but as locales are the only thing that affect stream output like that, it seems likely that locales were the issue. Anyway - I suspect your default C++ locale (which isn't necessarily the same as what your regional settings say!) is set to "C", a.k.a the 'classic' locale, like mine.
No, I don't know what sets the default C++ locale...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you for your help
I'm always feel insufficiency about <locale> library.
Could you share your knowledge about the 'locale'.
It's always big problem of me.
I think the article about 'locale' is very valuable thing.
Thanks!
|
|
|
|
|
I have a C/C++ program (yes, a mix of both) that acquires data from a hardware device and displays it in real time. I want to add some processing on the data as soon as I read it, but I want to make sure it doesn't slow down the data acquisition too much. Is there a utility that will measure how long a function takes or how often it is called?
I already use the Red Gate ANTS profiler for my .NET apps, but it doesn't work with native code. Also, any profilers I've tried tend to slow down the application quite a bit. Is there a way I can measure the execution time without affecting it too?
Or would it be best to use the clock() function from time.h to measure this?
Thanks,
Dybs
|
|
|
|
|
Hi,
I would not use external tools for this. They tend to be rather complex for the task at hand. Instead add a little piece of code.
Have a look at multimedia timers[^]; make sure you first determine their accuracy, it can be worse than 1 msec (up to 16 msec is common).
If that is not good enough, google for code that relies on the RDTSC assembly instruction.
|
|
|
|
|
To add to Luc's answer - I've always used the high-resolution performance counter[^] to time my code. I've got a class that encapsulates the whole process in an RAII fashion - something like:
class CTimer
{
public:
CTimer(std::string const& what) : what_(what) { QueryPerformanceFrequency((LARGE_INTEGER*)&freq_); begin_ = Now(); }
~CTimer() { end_ = Now(); ShowTime(end_ - begin_); }
private:
__int64 Now()
{
__int64 now;
QueryPerformanceCounter((LARGE_INTEGER*)&now);
return the time you calculated;
}
void ShowTime(__int64 deltaTime) { std::cout << "Doing " << what_ << << std::endl; }
__int64 begin_, end_;
__int64 freq_;
const std::string what_;
};
{
CTimer t("some message");
}
I've left out the involved bits (calculating time from QueryPerformanceCounter result and displaying the time nicely) as I don't have access to the code I wrote right at the moment.
Certainly don't use clock() - it's a milli-second timer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the answers. The reason I mentioned clock() is precisely because it's a millisecond timer. I'm not certain exactly how fast the data acquisition is now, but I don't think it's any faster than once a millisecond. When I add my processing code, I'd like to get as accurate as I can on how much it affects the timing, if at all.
I was looking at the link from Luc and saw the reference to QueryPerformanceCounter . I've seen other references to it on CP, but haven't needed to use it yet. Looks like it should do what I need.
Thanks again for the suggestions,
Dybs
|
|
|
|
|
|
I am working with some C++ code (not my code, of course) that has a bunch of huge functions, which I would like to refactor. Does anyone know of a utility that will scan C++ source files and report the number of lines in each function?
Jim Scott
|
|
|
|
|
I think this one[^] will do that
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Tried CCCC on a MFC program and it choked on all the special defines (macros) one is using when dealing with the win32 API.
|
|
|
|
|
You could well be right - I used it on embedded system code, and we didn't have much 'macro magic'.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks. This is a nice tool, and it gives a lot more information than I expected.
|
|
|
|
|
Here is list of SLOC metric tools:
LOC Metrics - Alternative Tools[^]
Source Monitor[^] seems to provide what you need, as it can provide a quick overview of all methods and how many statements they have. Just create a baseline and right-click the baseline and choose "Display Method Metrics...."
Also I would recommend to use Doxygen to see call hierarchies and class diagrams.
|
|
|
|
|
Hi,
im using Wshell.Regwrite to write registry(vb script) through html page...
but it works fine only when the option "Initialize and script ActiveX
controls not marked as safe" under Tools\internet
options/Security/Customlevel/ActiveX controls and plugIns ,is set to prompt or enable .....and if we set to any other option ie(disable) it fails ie it shows error like .. "ActiveX component cannot create object "Wscript.shell"...
So May i know whether is it possible to create my own ActiveX control(signed) with certificate(using c++) and embed in my vb script so that it doesn"t depend on internet options..
if yes pls let me know how to do the same...
pls correct me if im wrong...
|
|
|
|
|
You can make an ActiveX Safe for scripting via the interfaces IObjectSafetyImpl and IObjectSafetySiteLockImpl. Search for the complicated details in the MSDN.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I wrote an override for the OnNcPaint. It works fine, but I have a problem.
I want Windows to do the painting in a part of the NC area and let me do the painting for the remaning part.
More precisely, I want windows to draw the menu and let me do the remaining of the painting.
My ideea is to paint what I need then send a WM_NCPAINT message and a handle in wParam to the region where I want Windows to do the painting. The problem is that SendMessage drowns in some ATL code (I'm unfamiliar with ATL).
The error is about accessing an invalid address. I suppose Windows cannot access the definition of the region referred by my region handle. I think I'm supposed to do some sort of marshalling of the HRGN object, but as I said, I'm unfamiliar with ATL. Can somebody help ?
|
|
|
|
|
CString(0xcccccccc) wrote: More precisely, I want windows to draw the menu and let me do the remaining of the painting.
The way to do that is (in your WM_NCPAINT handler) to call DefWndProc, then do your painting. Don't send any extra messages or anything.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Tried this one, unsuccessfully:
::DefWindowProc(m_hWnd, WM_NCPAINT, (WPARAM) pRgn->m_hObject, pMsg->lParam);
|
|
|
|