LearnCPP | Learn Cpp from Beginner to Advanced ✅ Practice 🎯 Code 💻 | Learning library
kandi X-RAY | LearnCPP Summary
kandi X-RAY | LearnCPP Summary
Learn Cpp from Beginner to Advanced ✅ Practice 🎯 Code 💻 Repeat 🔁 One step solution for c++ beginners and cp enthusiasts.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of LearnCPP
LearnCPP Key Features
LearnCPP Examples and Code Snippets
Community Discussions
Trending Discussions on LearnCPP
QUESTION
From this post, I can conclude that there're 2 main ways (there may be other ways, of course) of declaring a new widget in Qt:
- Not using
new
keyword:
ANSWER
Answered 2021-Jun-01 at 18:25All QObjects will delete their own child objects automatically. (See docs here.) QWidgets are QObjects. So as long as you establish a parent/child relationship, you do not need to manually delete your objects. To do that, simply pass a pointer to the parent object to the constructor:
QUESTION
Following a tutorial on learncpp.com which discusses declaring member variables outside of constructors. However in previous lessons the author mentions that minimizing the amount of constructors is optimal and can be done by using default values in the parameters of a constructor. This is confusing to me because suddenly there are two places to give default values, directly where you define your member variable, and in the parameter of the constructor. Additionally, it seemed like the whole point of defining default values outside of the constructor was to prevent redundant code because "if you update the default value for a member, you need to touch each constructor".
Here's the example used:
...ANSWER
Answered 2021-May-30 at 16:06You can rewrite your constructors to not have any default parameters by adding some constructors
QUESTION
#include
#include
#include
#include
#include
using namespace std;
int main()
{
SQLHSTMT retrieveNumber;
SQLUINTEGER IDNumber;
SQLINTEGER IDNumberInd = 0;
SQLRETURN rc;
// Tried creating SQLWCHAR here to input to SQLPrepare but gives me:
// 'argument of type "SQLWCHAR" is incompatible with parameter of type "SQLWCHAR *"'
wchar_t text{ *"SELECT * FROM Table_1" };
SQLCHAR statementText1{ text };
SQLPrepare(retrieveNumber, statementText1, SQL_NTS);
}
...ANSWER
Answered 2021-Apr-18 at 21:52Your text
and statementText1
variables are declared all wrong.
You are dereferencing a pointer to a narrow string literal, thus accessing its 1st char
acter, which you then assign to text
, which is declared as a single wchar_t
.
You are then assigning that wchar_t
to statementText1
, which is declared as a single unsigned char
.
You are then passing that single character to SQLPrepare()
, but it expects a pointer to a (non-const) null-terminated string instead, thus the compile fails.
Try this instead:
QUESTION
I'm becoming familiar with using vectors (reading An introduction to std::vector), and it displays the following code as an example:
...ANSWER
Answered 2021-Mar-13 at 03:20(i.e. std::string
No, string literals are not related to the class std::string
. Technically this could happen if vector had a special deduction guide for this, but it doesn't.
... char*
No, string literals are const.
The contained type will be deduced as const char*
.
QUESTION
I'm reading about dynamic arrays (specifically at https://www.learncpp.com/cpp-tutorial/dynamically-allocating-arrays/), and it seems to me that dynamic arrays are not actually dynamic, in that the size allocated for them cannot be changed.
If I am understanding correctly, the main use or point of dynamic arrays vs fixed arrays is that dynamic arrays will be allocated on the heap rather than the stack, and therefore can be larger. The terms "dynamic" and "fixed" give me the impression that one can be changed and the other cannot, but it doesn't seem to be the case.
Is this correct, or am I misunderstanding something about dynamic vs fixed arrays?
...ANSWER
Answered 2021-Mar-11 at 04:11Dynamic arrays are dynamic i.e. they have dynamic lifetime / dynamic storage (i.e. they are stored in free store aka "heap").
Dynamic arrays are also dynamic in the sense that unlike array variables, their size can be determined at runtime i.e. it doesn't need to be compile time constant. Example:
QUESTION
I'm using MS Visual C++ 6.0 (as my work requires) on a pretty decent Windows 10 PC.
I'm having trouble with displaying the value after the decimal that is entered manually via "cin >>", I've tried the fix that was answered thru DSKVP's question (Show two digits after decimal point in c++) but it still won't show the decimal values, it just drops the digits after the decimal and/or rounds them off.
...ANSWER
Answered 2021-Mar-01 at 08:40I tested your code, and the only thing I changed was the return type of readResults()
from int
to double
. Once I did that, I got the results I expected!
QUESTION
As per this article, which says that( emphasis mine ):
Partial template specialization allows us to specialize classes (but not individual functions!)
It seems that function partial template specialization is not allowed. Is that really correct?
What confuses me is that why these code snippets could be compiled successfully:
...ANSWER
Answered 2021-Jan-02 at 05:33Is function template specialization really allowed?
Yes, but not partial specialisation.
It seems that function partcial template specialization is not allowed.Is it really correct?
If you mean partial specialisation, that is indeed not allowed for function templates.
QUESTION
I produced my own class long_number to proceed mathematical operations for higher numbers than long long int (for prime numbers purpose, etc. ). Now I am testing the addition and comparing the speed on the following code:
...ANSWER
Answered 2020-Nov-05 at 00:20Your long_number operator+
can easily be improved by eliminating multiple copies of the vector in get_numero()
.
You don't really need to make a copy of your vector to then ask for its size. Just provide a size()
method for your class.
Similarly, instead of (a.get_numero())[i]
(that, again, makes a copy of the entire vector before indexing into it), implement operator []
to directly access individual digits.
1,000 times longer that addition - it's a lot! however, something like 100 times would be expected - just count how many steps you have in place of a simple add
instruction
QUESTION
I have a C++ program:
...ANSWER
Answered 2020-Sep-25 at 01:44char bar[] = "";
QUESTION
I'm studying C++ using the website learncpp.com. Chapter 0.5 states that the purpose of a compiler is to translate human-readable source code to machine-readable machine code, consisting of 1's and 0's.
I've written a short hello-world program and used g++ hello-world.cpp
to compile it (I'm using macOS). The result is a.out
. It does print "Hello World" just fine, however, when I try to look at a.out
in vim/less/Atom/..., I don't see 1's and 0', but rather a lot of this:
ANSWER
Answered 2020-Aug-22 at 01:42They are binary bits (1s and 0s) but whatever piece of software you are using to view the file's contents is trying to read them as human readable characters, not as machine code.
If you think about it, everything that you open in a text editor is comprised of binary bits stored on bare metal. Those 1s and 0s can be interpreted in many many different ways, and most text editors will attempt to read them in as characters. Take the character 'A' for example. It's ASCII code is 65 which is 01000001 in binary. When a text editor reads through the file on your computer it is processing those bits as characters rather than machine instructions, and therefore it reads in 8 bits (byte) in the pattern 01000001 it knows that it has just read an 'A'.
This process results in that jumble of symbols you see in the executable file. While some of the content happens to be in the right pattern to make human readable characters, the majority of them will likely be outside of what either the character encoding considers valid or knows how to print, resulting in the '�' that you see.
I won't go into the intricacies of how character encodings work here, but read Character Encodings for Beginners for a bit more info.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install LearnCPP
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page