Click here to Skip to main content
15,880,608 members
Everything / Programming Languages / C++

C++

C++

Great Reads

by Dr. WPF
.NET 3.5 SP1 is here! It's time to break out your DirectX skills. This article provides the information necessary to get started using a new DirectX interop feature in WPF called D3DImage.
by Hatem Mostafa
Artificial Neural Network C++ class with two use cases: Counter and Handwritten Digits recognition
by Jeffrey Walton
Import and export Cryptographic Keys in PKCS#8 and X.509 formats, using Crypto++, C#, and Java.
by Hans Dietrich
XColorSpectrumCtrl displays a color spectrum that allows user selection, and provides APIs for color based on RGB and HSL color models.

Latest Articles

by PJ Arends
Trace your function calls to the Output window.
by Ștefan-Mihai MOGA
Task Manager shows you the programs, processes, and services that are currently running on your computer. You can use Task Manager to monitor your computer’s performance or to close a program that is not responding.
by Mohammed Faci
How to leverage ChatGPT to Build an Automation Framework using the Page Object Model
by Igor Gribanov
C++ iterators and algorithms work well for containers, but can we sort the Structure of Arrays?

All Articles

Sort by Title

C++ 

24 Jul 2018 by 서형박
#include #include #include using namespace std; class Fir { public: virtual void mfunc() { cout
24 Jul 2018 by Gerry Schmitz
Virtual methods are used "as is"; or you "override" them; you have done neither; you have simply created a "replacement" virtual method in each class. Trying to "down cast" in this situation makes no sense.
24 Jul 2018 by CPallini
That's the very purpose of the virtual functions: to allow polymorphism. Consider, for instance the following code void draw_shapes( Shape * sh[], size_t count) { for ( size_t n = 0; n draw_myself(); } every item of the array (every Shape) will draw itself depending...
8 Oct 2016 by OriginalGriff
We really still do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you...
9 Oct 2016 by Richard MacCutchan
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx[^].
8 Oct 2016 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you may find it...
8 Oct 2016 by OriginalGriff
We still do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you may...
19 Oct 2016 by star start
This is my eror and I can not fix it.Visual Studio 2015 ( C++ project )Error C1189 #error: Macro definition of snprintf conflicts with Standard Library function declaration test_project c:\program files (x86)\windows...
19 Oct 2016 by KarstenK
The compiler tell you the truth: You cant define some macro (or function) like snprintf, because the name is already usd in the standard library.The names have to be unique to get language conform. Tip: find a mate to learn the language better ;-)
28 Mar 2019 by Member 13508014
#include using namespace std; class Test { private: int mx; float my; int medata; //some extra data public: Test() { mx = my = medata = 0; } Test(int x, float y, int edata) { mx = x; my = y; medata = edata; } void print() { cout
28 Mar 2019 by CPallini
See the "Binary arithmetic operators" section of operator overloading - cppreference.com[^] for a guideline.
28 Mar 2019 by steveb
There are three rules for writing binary arithmetic operator: 1. You also must write a compound operator, += in your case. 2. Your compound operator must return a reference MyClass & MyClass::operator+=(const MyClass &rhs) { ... return *this; } 3. Define your binary arithmetic...
28 Mar 2019 by Stefan_Lang
It sounds like you're trying to merge to kinds of objects into one: one that has an intuitively understandable concept of summation, and another that doesn't. Still they are related somehow to the point that you want to have them inside a common ... container. I'd suggest to separate your...
5 Sep 2001 by Marat Bedretdinov
Shell interfaces in use. IShellFolder, IEnumIDList, etc.
10 Jun 2010 by jp2code
I have a library that is published by a governmental, non-profit organization on how to generate models from data. It supplies a library file (coilmodel.dll) and a header (coilmodel.h).From the header, I see there are only four (4) exported methods that our applications will need.If I...
10 Jun 2010 by Fredrik Bornander
As long as the dlls are in a location that your application can find it's easy to import them to C#. One such place is in the same folder as your application (so just copy them to the bin\Debug folder.Since all the methods exported in the example above uses primitives all you have to do is...
21 Apr 2012 by Hrushikesh_phapale
#include
18 Mar 2012 by Mallikarjunarao Kosuri
#include #include using namespace std;int main() { int words,chars; string line; cout
2 Mar 2012 by smss IR
Hi.I was writing on c++ and when i go to define a object from a class with the name "catch", i noticed this is a command such as "int" or "double" .I wanna informations about "catch", because i curious about it.Thanks.
2 Mar 2012 by JackDingler
'catch' is a reserved word, used in exception handling.It allows for a function to abort processing in case of an error, in a safe manner.When an exception is thrown, objects on the stack are properly unwound and their destructors called. The appropriate catch statement in the try /...
4 Mar 2012 by Sergey Alexandrovich Kryukov
Please see:http://en.wikipedia.org/wiki/Structured_exception_handling[^].This is one of the most fundamental and important inventions in programming of all times and peoples, mostly pioneered by Barbara Liskov at al (http://en.wikipedia.org/wiki/Barbara_Liskov[^]).Today, anyone using...
29 May 2003 by Nicolas Bonamy
Simulate the Class Wizard in VS.NET 2003
4 Feb 2003 by Nicolas Bonamy
Two simple ways to add "Do not ask again" Message Boxes to your application.
29 Nov 2020 by honey the codewitch
I am not so hot at traditional math sometimes. Give me set theory and lambda calculus please! I am trying to basically downsample some data I am receiving in real time. I sample it initially at 10Hz but then I need to downsample the data to 1Hz...
29 Nov 2020 by Patrice T
float data = readNextPoint(); _interpolateX = (_interpolateX + data) /2; // last data is half the final result I would rewrite the code like: float _interpolateX=0; int _interpolationCount=0; while(1) { _interpolateX=0; for...
29 Nov 2020 by k5054
I think what you are trying to calculate is a moving average. In any case, I don't think you can add and divide by two to get the right answer e.g. What you want is : (7+ 5 + 9 + 4 + 3)/5 = 5.6 What you are calculating (((((0+7)/2 + 5)/2 + 9)/2...
29 Nov 2020 by Rick York
Here's a template class I wrote a while ago I call a WindowFilter. It is essentially a moving average as K5054 mentioned previously. In your case, you could set the size of the window to be 10 and it will give you the average of the last 10...
16 Aug 2012 by DrBones69
What could be wrong with this? It was working fine and then...Improper Argument.Could it have something to do with deleting records from the array?for(int i = 0; i
16 Aug 2012 by nv3
Your best friend is as in most cases your debugger. But from just looking at the code I would suspect that nItem = m_ListCtrl.InsertItem(0, FirstName[i] + L" " + LastName[i]);might return -1 when not successful (for whatever reason) and the following ...
17 Aug 2012 by DrBones69
I was trying to read my arrays beyond the amount of data that the arrays had stored. This is what I did to fix this issue:s7 = (((_wtof(myData[nPos].m_sPrice7) / _wtof(myData[nPos].m_sQty7)) - _wtof(myData[nPos].m_sCost7)) * _wtof(myData[nPos].m_sQty7)); t7.Format(L"%.2f",...
21 Feb 2013 by kavinsp
Hi , i am writing a web socket server implementation in c++, but i am getting this error "Error during WebSocket Handshake: Sec-WebSocket-Accept Mismatch" in console.Do you have any idea of what goes wrong for getting this error??RegardsKavin
15 Oct 2012 by Cpp For All
finally like clause in C++
4 Apr 2011 by Dave Kreskowiak
Nobody is going to give you the code. The point behind the assignment is to see if you learned the material in class. It is NOT to show off your "begging for someone to do my work for me" skills.Google results for "Self Organizing Map[^]"Google results for "Particle Swarm Optimization[^]"
12 Nov 2007 by Lou Franco
Atalasoft leverages their DotImage toolkit to manipulate color channels for the purpose of image enhancement, in this case satellite images. The article is a tutorial on image enhancement and it includes all source code and test images.
21 Jan 2013 by zqliu
f1(), f2(), f3() is a function of type bool, which of the following style is better? A. if (f1 () && f2 () && f3 ()) do (); B. if (f1 ()) if (f2 ()) if (f3 ()) do ();If three function execution time is longer, is B method is better? Or they are just the same...
21 Jan 2013 by PIEBALDconsult
They should be about the same. I prefer A; it's more polished. Any fool can do B.
21 Jan 2013 by nv3
It actually doesn't matter from a run-time point of view. In other words, A and B will run equally fast. For readability purposes, however, I would always prefer A. or better yetif (f1() && f2() && f3()) doSomething ();
21 Jan 2013 by Abhinav S
I'd prefer A. If (f1 () && f2 () && f3 ()) do (); because it is much more clearer and easier to understand.You are using && which is a short circuit operator.If the first condition fails the second won't execute so there will be no difference in execution time in either case.
21 Jan 2013 by Andreas Gieriet
You left out a 3rd variant:bool hasSomethingToDo = f1() && f2() && f3();if (hasSomethingToDo){ DoSomething();}and a 4th variant:bool hasSomethingToDo = f1() && f2() && f3();if (hasSomethingToDo){ DoSomething();}Usually,...
21 Jan 2013 by H.Brydon
Any C/C++ compiler nowadays will treat both the same way and generate either the same code or almost the same code.A point perhaps more important than performance for this one-liner is maintainability. In most cases, 'A' is the better choice - if the logical tests are truly function names or...
12 Feb 2011 by PrafullaVedante
Avoid using "if" with no code block parenthesis
10 Feb 2011 by Andrew Rissing
Always review all changes before submitting them. Especially, if using a global find and replace.
17 Feb 2011 by paladin_t
Whatever, I agree with you, it would be worse in C / C++ code using macros.Suppose you got a multiline macro like this:#define some_macro \ do_something_1(); \ do_something_2();And using this macro without parenthesis:if(...) some_macro;orfor(...) ...
20 Jun 2010 by katrin.jungbrecht
What I want:I want that all of my child classes are able to return their name as string (using a common function GetName()).The GetName function has to be accessible through the base class pointer, returning the name of the specific child class.My idea:1. I use an abstract...
20 Jun 2010 by CPallini
What's wrong withclass Base{ public: const char* GetName() const { return typeid(*this).name(); }};?
20 Jun 2010 by #realJSOP
Just put a public method in the base class that returns the name of the object represented by the this pointer. It doesn't even have to be pure virtual.
20 Jun 2010 by katrin.jungbrecht
I thought already thought about that (putting the function as public member function into the base class), but this does not work.#include #include class Base{public: const char* GetName() const { return typeid(*this).name(); }};class Child :...
20 Jun 2010 by Aescleal
Typeinfo is bound statically when a class doesn't have any virtual functions - the compiler works out which typeinfo to use at compile time. If you have one virtual function then the type_info is looked up at runtime from the v_table. If you define base the way you do in the third answer or...
24 Jan 2014 by Member 20
HiI am using RPC Client and Server interface. I am able to build in 32 bit but when I change it to 64 bit, I am getting error "Invalid build platform for this stub" and it is pointing to below lines:#if !defined(__RPC_WIN32__)#error Invalid build platform for this stub.#endifHow to...
24 Jan 2014 by OriginalGriff
See here: MSDN: Targeting Stubs for Specific 32-bit or 64-bit Platforms[^]
7 Apr 2023 by Zouaoui Billel
Hello All; I am working on C++/MFC project where I need to use access control device SDK acualy I registred SKD DLL (using regsvr32.exe) to create a controller, after that I Open my MFC project and I added activex controller from the wizard, ...
16 Mar 2023 by Zouaoui Billel
Hello All; I am working on C++/MFC project where I need to consume an active x control, so I create a control like CZKEM1 m_zktecoCtrl; but when I try to invoke it Like bool bConnect = false; bConnect =...
16 Mar 2023 by CPallini
Someone here would (correctly) write: "This is not a good question [...]". As Richard pointed out, at least one argument is expected. You should post here, at least, the Read method prototype in order to get meaningful help. [update] Your...
16 Mar 2023 by Richard MacCutchan
As far as I can see your code should not compile, because of: static BYTE parms[] = VTS_BSTR VTS_I4; The elements of an array should be separated by commas, thus: static BYTE parms[] = { VTS_BSTR, VTS_I4 }; ...
16 Dec 2016 by mayashah
Hi !!i want to ask a little question i learned this from some site !! i dont know what does this means also i want its alternate in form of " new " if any (dynamic memory)" new_node = (struct node *)malloc(sizeof(struct node)) " // here i am encountering problems and please tell me its...
16 Dec 2016 by OriginalGriff
malloc is a library function which is short for "memory allocate" - and it's job is to return a pointer to a free block of memory which is the size you specify in the parameter. You can then cast that pointer to whatever type you need to use it for, and use it as an instance of that structure....
16 Dec 2016 by Jochen Arndt
malloc - cppreference.com[^] (Edit: for Memory ALLOCation) is a function from the C standard library to allocate memory from the heap.It can be still used with C++ but new should be used instead (see also std::malloc - cppreference.com[^]) .One difference is that malloc returns a void*...
16 Dec 2016 by Patrice T
You should really take time to learn properly C/C++.Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.The C Programming Language - Wikipedia, the free...
1 Nov 2012 by Sidra Feroze
my compiler is giving me this error"function 'menu' should have a prototype!what is its prototype? pleeease some one help me
1 Nov 2012 by Nelek
A bit theory:http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V40F_HTML/AQTLTBTE/DOCU_055.HTM[^]http://en.wikipedia.org/wiki/Function_prototype[^]Other people with the same...
2 Nov 2012 by Sajeesh Payolam
Read following link carefully. which explained wellhttp://en.wikipedia.org/wiki/Function_prototypeanother one ishttp://cboard.cprogramming.com/c-programming/69745-what-does-prototype-c-mean.html
15 Jan 2012 by mot sach
when i compile my source code ""g++ main.cpp Test.cpp", i have met error:"/tmp/ccSer90m.o: (.bss+0x0): multiple definition of `Test::count'/tmp/cc7iaBlq.o: (.bss+0x0): first defined herecollect2: ld returned 1 exit status"File "Test.h":class Test{public: ...
15 Jan 2012 by «_Superman_»
The definition (int Test::count = 0;) must be put in a .cpp file and not in a header file.
15 Jan 2012 by tolw
Try moving this line:int Test::count = 0;from the .h file to the .cpp file.The problem is that each time you include "Test.h" the count variable gets defined - hence multiple definitions. Moving the line to the .cpp file ensures that there is only one definition of count.
12 May 2011 by Member 7766180
The reason this is not working is that MYSQL_ROW row and an integer of 1 or 0 are not of the same data type. How would i make them the same data type? mysql_query(conn,"SELECT COUNT(*) FROM tblURL WHERE IP = '192.168.1.399' AND Status = 'Active'"); my_ulonglong i =...
12 May 2011 by Albert Holguin
first off...in an if statement: if(x = 1) //
13 May 2011 by Richard MacCutchan
Take a look at the documentation here[^], which explains the data types returned by MySQL functions. mysql_fetch_row() returns a database row not an integral value.
11 May 2011 by markfilan
I am tryig to change a 32bits driver to 64bits,here is the problem, i can not correct this:the error shows below:1>D:\WinDDK\7600.16385.1\inc\api\ntdef.h(155): fatal error C1189: #error : "No Target Architecture"1> Dispatch.cpp1>D:\WinDDK\7600.16385.1\inc\api\ntdef.h(155): fatal error...
11 May 2011 by Richard MacCutchan
I don't have a copy of the DDK but my suggestion would be to look in D:\WinDDK\7600.16385.1\inc\api\ntdef.h around line 155 and try to figure out what preprocessor definition you have not set.
12 May 2011 by Albert Holguin
The DDK expects some environment variables to be set, see this:http://mcdermottcybersecurity.com/articles/64-bit-device-driver-development[^]Now, you can use the building tools that the DDK uses which already set these variables for you or you can just set them yourself by whatever means...
17 Jan 2012 by Bram van Kampen
Where do I Find this elusive Header File: "Ntddstor.h"Regards,:)Bram
17 Jan 2012 by Albert Holguin
See remarks section here.[^]To download the WDK... http://msdn.microsoft.com/en-us/windows/hardware/gg487463[^]
17 Jan 2012 by loctrice
It is on source forge. It is the first link in google if you type in :"where is Ntddstor.h"Google Search[^]
7 Mar 2012 by Randor
Bram,I know its been two months since you posted this question. I am not sure if you have found the header file yet... if not then you will need to download the latest Windows DDK (as Albert pointed out) and the header file is located in the \7600.16385.1\inc\api folder.I would not...
7 Mar 2012 by Chandrakantt
You can find this under WDK at below location of Vista and Windows 7 WDKwinddk\6001.18002\inc\apiwinddk\7600.16385.0\inc\apiwinddk\7600.16385.1\inc\api
13 Sep 2009 by Sanjeev Venkat, kb-boxer
Are your classes that implement the Template Method Design Pattern "Decorator aware"?
23 Dec 2021 by carlmack
why is it i am getting from this block (12,1) qualifier PMatrix is not a class or namespace, and Declaration terminated incorrectly?#include #include #include /*#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new...
23 Dec 2021 by jjara_rbs
That is code from the Professor Sergio Pissanetzky’s book. The links to download the source codes of this books do not works.(https://www.SciControls.com/eBooks/…) You can share the following files with me: VectorMatrix.zip...
11 Sep 2012 by Super Lloyd
Yesterday I was practicing my rusty C++ and trying to learn DirectX on Windows 8.One of the (WinRT, C++/CX) sample had a class like thatref class A{private protected: int num;}Now I'm confused.. what is this 'private protected' thing?I know protected (only accessible to...
11 Sep 2012 by Jochen Arndt
See Member Visibility[^] in the MSDN.
6 Nov 2009 by hxhl95
Escalating a process to system critical status using a Win32 kernel function
16 Apr 2001 by Igor Sukhov
The ATL and MFC versions of the class that implements a dialog for selecting users(computers) within the Windows Network.
27 Mar 2007 by vishalkmehta
This article demonstrates how to leverage the power of images and inheritance to achieve a "skinned" look for your Windows applications.
28 Mar 2013 by WaZoX
I am about to implement a doubly-linked list (the default std::list doesn't fit my needs because I need direct access to the internal nodes). My question is if I should use "std::allocator" or the keyword "new" when implementing it. I understand the power with "allocator" but I don't plan to...
28 Mar 2013 by Sergey Alexandrovich Kryukov
It's totally up to you. This feature is used to give the user access to allocation method, to provide an alternative allocator. In the code using the container, it could be a sub-allocator or something, used to boost performance, taking into account the particular order of...
19 Sep 2006 by tanvon malik
This article shows you ways to run Control Panel applets from VC++, even those that don't have a cpl extension file.
26 Oct 2012 by steven8Gerrard
What does representation in 0*0x100u mean in C . If it end with "b" . I know its binary . What is "u"
26 Oct 2012 by BobJanova
U means unsigned, there's a full set here[^].
26 Oct 2012 by psychic6000
u is for unsigned, btw if you are multiplying it by 0 then it doesnt matter...
2 Aug 2012 by ahsanriaz1K
Hi all,I am using "u_strToUTF8()" in my function "UnicodeToString()" to convert a unicode string to string. All was going fine but it is destroying the value of string having arabic data.Is there any solution?Here is code , just for...
2 Aug 2012 by pasztorpisti
Short answer:UChar is a 16 bit integer so I guess that unicodestring stores the string in utf16. Actually utf16 is the native format of windows (not true for win9x versions) so you should just use this string with windows with the 'W' (utf16) versions of the winapi functions (I guess you don't...
2 Aug 2012 by Richard MacCutchan
I don't know where this function comes from but you may like to take a look at my tip: Handling simple text files in C/C++[^]. This shows how to convert using the standard Microsoft library functions, which also take account of the fact that the source and destination buffers may not be the same...
3 Sep 2010 by soheilasharifi
I have a problem with 'very verbose' macro.What is precise definition and main task of this macro?Whether is this macro for a particular operating system?How many argument neeeds this macro?
4 Sep 2010 by Paul Michalik
No, "very verbose" is not a valid c++ name for a macro. Please, specify what you exactly mean.
13 Apr 2018 by Karol Kulawiec
I don't get it. I've been staring at the code the code for a few hours and I don't know how I can fix it. The class I'm creating, called Weapon. This is how I defined the constructor: template Weapon (T1& A); This is how I implement the constructor: ...
13 Apr 2018 by KarstenK
you need also to implement this constructors because of the Weapon weapon;//object with default constructor Weapon egg; You need such code in the implementation Weapon::Weapon() { //set some useful defaults } Advanced technique: make pointers of the member and construct it somewhere else.
14 Sep 2013 by Member 10243685
Is windows.h header file available in Visual C++? If not where can I get it, can it be downloaded?
14 Sep 2013 by Sergey Alexandrovich Kryukov
It is available, but this is not just the include file.Including a header file itself does not make libraries accessible. You also need to link them. With Visual Studio, you can set all appropriate options (in particular, telling the compiler and the linker to look for certain files in...