|
"new" ... you can't instantiate an "abstract" class; you need to subclass it first or use an existing derived class.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
i wanna ask, what is the best environment for learning C++ for windows application? e.g. Win32 API, Qt, etc...
also, could anyone suggest what's the best e-books for references?
|
|
|
|
|
When (really) learning, they usually start you with Notepad and a command line compiler. The "environment" can suck up most of your time (and disk space).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
It depends on what you are trying to learn. If you know C++ then Win32 should be fairly easy. But if you do not know C++ then that is what you need to start with.
Here is a starter for C++: Learn C++[^]
And one for Windows: EFNet #Winprog[^]
|
|
|
|
|
I am compiling some old legacy code with MFC. For this line in cmath.h I get an error:
NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
return _CSTD roundf(_Xx);
}
With first round statement highlighted I get this message:
C2062 type'int' unexpected
|
|
|
|
|
You should inspect the calling code, I believe (the compiler provides full information with the error message).
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I don't understand that. It is a compile error in a core library file. I am not allowed to change it. Why would the calling function have anything to say?
|
|
|
|
|
Quote: Why would the calling function have anything to say?
Quote Selected Text With very high probability the calling code is wrong (possibly making incorrect assumptions on the called function, it passes the wrong type). Maybe a previous implementation of the library had relaxed checks on calling code correctness.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Use your development environment (VS or whatever) to check that there is a #define for each the following:
NODISCARD
_Check_return_
In
_CSTD
And if you're using C instead of C++, noexcept could be the problem. But I can't say, because I only write C++.
EDIT: type 'int' unexpected suggests that the caller is passing an int , not a float .
|
|
|
|
|
There are plenty of _Check_return_ statements that work.
If there is something wrong with the calling function, I should get a compile error when compiling the cpp file where the function is called? This is an error from inside the include file cmath.h.
Three errors reported, underscore is the highlighted error indication.
Line 210
_NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
return _CSTD roundf(_Xx);
}
Line 446
_NODISCARD _Check_return_ inline long double round(_In_ long double _Xx) noexcept /* strengthened */ {
return _CSTD roundl(_Xx);
}
Line 663
_GENERIC_MATH1(round)
It seems I am not allowed to alter any include file, so I can not experiment with commenting the functions out, etc.
|
|
|
|
|
Check if round is also defined somewhere else, and check that _GENERIC_MATH1 is actually defined. Beyond that, I don't know.
|
|
|
|
|
I would be inclined to look at the preprocessor output to see what all of those non-standard "types" are.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi,
I am going to point out that you are almost certainly looking at the wrong code location. The C2062 error usually really does mean the 3 letters 'int' were unexpected while parsing the code.
Look around for an int that is declared wrong.
|
|
|
|
|
Is that the full text of the error message? Also what are the few lines either side of that definition?
|
|
|
|
|
Your compiler should have an option to send the output of the preprocessor into a file. Using Visual C/C++, this option is /P, and the output file has an extension of .i .
Run your code through this, and look for cmath.h in the .i file. Then look for the definition of the round() function. You will see what the compiler thinks the round() function is, and your problem should then be obvious.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Hi and thanks for all help.
When I put
#include <cmath>
right under #include stdafx.h it compiled. Don't ask me exactly why. It may be a conflict between math.h and cmath that was solved in this way.
Regards, Haakon S.
|
|
|
|
|
So...
You said that your compiler gave you an error in cmath.h
Haakon S. wrote: For this line in cmath.h I get an error: Which you solved... "by including cmath.h"

|
|
|
|
|
I honestly don't know what is going on.
Some files had #include <math.h>. Removing this did't help. It reported error in cmath anyway.
When googling "cmath error c2062" I see that others have had the same problem.
Anyway, it seems that I have found the solution.
|
|
|
|
|
Ok C++ is not mt my main language so please bear with me.
For my question I will use this class
class BillingDates
{
public:
BillingDates(std::string InputFile);
void ProcessDates();
rapidjson::Document doc;
std::string InputFile;
std::string YearStartDate;
std::string YearEndDate;
std::string BBFDate;
std::string BillIssueDate;
std::string BillIssueDateLong;
int CurrentFinancialYear = 0;
std::ifstream InputStream;
};
And in my main program I declare a pointer and an object to the class thus
BillingData *bData;
BillingData bData2;
I can then create my pointer so
bData = new BillingDates("path to my file");
how can I create an instance for bData2 ?
I know I can do it like this
BillingData bData2("path to my file");
but that will create a new var and not use my previously declared var.
Hope this makes sense
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
If your code looks exactly like posted, compiler will slap you with an error on bData2 line because you don't have a default constructor. You can:
1. Modify the constructor to default to an empty string: BillingDates(std::string InputFile = std::string()) and handle the case when InputFile is the empty string.
2. Create an additional default constructor: BillingDates()
If you need to move data from bData to bData2 you might need a copy constructor: BillingDate (const BillingDate& other) .
Mircea
|
|
|
|
|
Hi and thanks for replying but the problem I have is I don't know the path to my input file until later in the program
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
In that case have a default constructor for initialization and add a function BillingDates::Open (std::string& file) that gets called when you have the path to your file.
You might also need something like bool BillingDates::IsOpen() const to check the state of the object.
Mircea
|
|
|
|
|
Have you tried:
BillingDates bData2("");
BillingDates* bData = &bData2;
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi and thanks for replying but the problem I have is I don't know the path to my input file until later in the program
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|