|
Tarun Jha wrote: ...but it is a collection of characters, so how is it a char ? The variable ptr is a pointer to a collection of char -acters, be it 1 or 100.
Tarun Jha wrote: ...then why it is called string literal ? Like anything holding quotation marks apart, they are literally those characters. They haven't been modified, translated, obtained from some other place, coerced, etc. If you look inside the compiled file, you will see those characters, literally.
"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
|
|
|
|
|
To me you are sort of asking a strange question well outside the literal string part, so lets just check you understand some basics
First a string is class or if you want an object it has constructors, destructor and methods it isn't just an array of characters.
string - C++ Reference[^]
You can't remotely equate those two lines as anything similar, do you understand that?
So with a string class when you declare it as a const (like your commented out) what are you expecting it will do?
So you are clear you are asking for a constant pointer to an object and trying to set some literal string to that object.
This may also help understand Victors response and David deals with the literal part.
The point here is you can only create a string when it matches one of the constructor types of the class.
What constructor functions exist controls how you can create it.
Here is the examples of showing the seven standard constructor methods for the class
string::string - C++ Reference[^]
The situation with just a character array is very different
const char *ptr = "tarun";
We have a simple array of characters that can never be changed AKA they are constant
Everything from a C to a C++ compiler understands the later because it's very trivial.
In vino veritas
modified 3-Apr-18 23:11pm.
|
|
|
|
|
Hi. I need to use OpenCV in some project, and I noticed that I have to compile myself OpenCV library.
So, I have downloaded the latest version from here: Releases - OpenCV library[^]
and I have generated the project file for VS2008, with CMake (using Windows 1064bit). All of these steps have been completed without any error. The problem begin when I have tried to compile the library itself ... I got a lot of errors:
...
...
45>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(356) : error C2065: 'uint_fast64_t' : undeclared identifier
45>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(358) : error C2065: 'uint_fast64_t' : undeclared identifier
45>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C2146: syntax error : missing ';' before identifier 'cvRound64'
...
...
Of course, I have read the tutorials about compiling OpenCV, seem to be ok how I get the steps ... but the errors persist ... if you have some experience with OpenCV, could you help me ?
Thank you.
|
|
|
|
|
Did you include the <stdint.h>?
|
|
|
|
|
 For the moment I am compiling the OpenCV library, and I didn't edit any source code. Perhaps I put too less information regarding the errors:
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(189) : error C2065: 'uint_fast32_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(189) : error C2146: syntax error : missing ';' before identifier 'vv'
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(189) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(190) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(314) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(321) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2146: syntax error : missing ';' before identifier 'vv'
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(331) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(332) : error C2065: 'vv' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(348) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(352) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(354) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(356) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(358) : error C2065: 'uint_fast64_t' : undeclared identifier
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C2146: syntax error : missing ';' before identifier 'cvRound64'
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Flaviu\opencv\sources\modules\core\include\opencv2/core/softfloat.hpp(393) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2059: syntax error : ')'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(47) : error C2365: 'base64::base64_encode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : see declaration of 'base64::base64_encode'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2059: syntax error : ')'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(49) : error C2365: 'base64::base64_decode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : see declaration of 'base64::base64_decode'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2143: syntax error : missing ')' before 'const'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2059: syntax error : ')'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(51) : error C2365: 'base64::base64_valid' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : see declaration of 'base64::base64_valid'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : error C2059: syntax error : ')'
1>..\..\..\sources\modules\core\src\softfloat.cpp(81) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\..\..\sources\modules\core\src\umatrix.cpp(482) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(137) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=char
1> ]
1>..\..\..\sources\modules\core\src\softfloat.cpp(81) : error C2146: syntax error : missing ';' before identifier 'globalDetectTininess'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(47) : error C2365: 'base64::base64_encode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(46) : see declaration of 'base64::base64_encode'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(137) : error C2064: term does not evaluate to a function taking 4 arguments
1>..\..\..\sources\modules\core\src\softfloat.cpp(81) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2065: 'uint8_t' : undeclared identifier
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2143: syntax error : missing ')' before 'const'
1>..\..\..\sources\modules\core\src\softfloat.cpp(97) : error C2448: 'raiseFlags' : function-style initializer appears to be a function definition
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : error C2059: syntax error : ')'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(154) : error C2064: term does not evaluate to a function taking 3 arguments
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(49) : error C2365: 'base64::base64_decode' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(48) : see declaration of 'base64::base64_decode'
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C2146: syntax error : missing ';' before identifier 'globalRoundingMode'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(163) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=uchar
1> ]
1>persistence_types.cpp
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2065: 'uint8_t' : undeclared identifier
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C2086: 'const int cv::uint_fast8_t' : redefinition
1> ..\..\..\sources\modules\core\src\softfloat.cpp(81) : see declaration of 'cv::uint_fast8_t'
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2143: syntax error : missing ')' before 'const'
1>..\..\..\sources\modules\core\src\persistence_xml.cpp(180) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=uchar
1> ]
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : error C2059: syntax error : ')'
1>..\..\..\sources\modules\core\src\softfloat.cpp(119) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(51) : error C2365: 'base64::base64_valid' : redefinition; previous definition was 'data variable'
1> c:\flaviu\opencv\sources\modules\core\src\persistence.hpp(50) : see declaration of 'base64::base64_valid'
1>..\..\..\sources\modules\core\src\persistence_yml.cpp(100) : error C2039: 'data' : is not a member of 'std::vector<_Ty>'
1> with
1> [
1> _Ty=char
1> ]
1>..\..\..\sources\modules\core\src\persistence_yml.cpp(100) : error C2064: term does not evaluate to a function taking 4 arguments
1>..\..\..\sources\modules\core\src\persistence_yml.cpp(117) : error C2064: term does not evaluate to a function taking 3 arguments
1>..\..\..\sources\modules\core\src\softfloat.cpp(167) : error C2146: syntax error : missing ';' before identifier 'f32_to_i32'
and it count for ever ...
|
|
|
|
|
Where should I insert this header ?
|
|
|
|
|
If you are using precompiled header then in stdafx.h.
Otherwise - at the begin of the .hpp file that needs these type definitions (uint_fast64_t and so on)
|
|
|
|
|
I have no experience with OpenCV but the reason for those errors is obvious.
Quote: I have generated the project file for VS2008 The int_fast and int_least types has been introduced with C++11 and are supported by Visual Studio since VS 2015 (see Standard Types[^]).
You might define them yourself as
typedef uint64_t uint_fast64_t;
You might also check if using C++11 is set somewhere in the OpenCV make file and disable that in the hope that the types are then defined somewhere.
|
|
|
|
|
the following question is to be done using the concept of hierarchical inheritance
staff - > teacher, officer, typist
typist -> regular, casual
my solution is giving an Runtime error
below is my code :
#include <iostream>
#include <string>
using namespace std;
class staff {
string code, name;
public:
staff() : code(0000), name("Unknown") {}
virtual void getdata(void){
cout << "Enter employee name : " << endl;
getline(cin, name);
cout << "Enter employee code : " << endl;
cin >> code ;
}
virtual void putdata(void){
cout << "Employee name : " << name << endl
<< "Employee code : " << code << endl ;
}
};
class teacher : public staff {
string subject;
int publication;
public:
teacher() : subject("Empty"), publication(0000) {}
void getdata(void);
void putdata(void);
};
void teacher::getdata(){
staff::getdata();
cout << "Enter subject : " << endl ;
cin >> subject;
cout << "Enter total number of publications : " << endl ;
cin >> publication ;
}
void teacher::putdata(){
staff::putdata();
cout << "Subject : " << subject << endl
<< "publications : " << publication << endl;
}
class officer : public staff {
int grade;
string posting ;
public:
officer() : grade(0), posting("Unavailable") {}
void getdata(void);
void putdata(void);
};
void officer::getdata(){
staff::getdata();
cout << "Enter the grade : " << endl;
cin >> grade;
cout << "Enter the posting : " <<endl;
getline(cin, posting);
}
void officer::putdata(){
staff::putdata();
cout << "Officer Grade : " << grade << endl
<< "Officer Posting : " << posting << endl ;
}
class typist : public staff {
int speed;
float experience;
public:
typist() : speed(0), experience(0) {}
virtual void getdata(void);
virtual void putdata(void);
};
void typist::getdata(){
staff::getdata();
cout << "Enter typing speed :- (word/second) : " << endl;
cin >> speed;
cout << "Enter experience (int years) : " << endl;
cin >> experience ;
}
void typist::putdata(){
staff::putdata();
cout << "Typing speed ( words/second ) : " << speed << endl
<< "Experience ( in years ) : " << experience << endl ;
}
class casual : public typist {
double daily_wages;
public:
casual() : daily_wages(100) {}
void getdata(void);
void putdata(void);
};
void casual::getdata(){
typist::staff::getdata();
cout << "Enter the daily wage : " << endl ;
cin >> daily_wages;
}
void casual::putdata(){
typist::putdata();
cout << "Daily waged : " << daily_wages << endl ;
}
class regular : public typist {
double monthly_wage;
public:
regular() : monthly_wage(3000) {}
void getdata(void);
void putdata(void);
};
void regular::getdata(){
typist::getdata();
cout << "Enter Monthly wage : " << endl ;
cin >> monthly_wage;
}
void regular::putdata(){
typist::putdata();
cout << "Monthly wage : " << monthly_wage << endl;
}
int main(){
regular r1;
r1.getdata();
r1.putdata();
return 0;
}
i am not able to understand the following error:
Quote: terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Thank you
|
|
|
|
|
You need to use the debugger to find out exactly where the error occurs.
|
|
|
|
|
what is the error saying ?
|
|
|
|
|
It's probably saying that you are trying to access some element that has not been initialised. And looking at your classes I cannot guess where is the most likely place. Although most of the code is not doing things in the best way.
As I have previously suggested to you, you need to get a book on C++ and learn it properly from beginning to end. You cannot learn it by continually posting questions.
|
|
|
|
|
i am currently following "C++ The complete reference by : Herbert Schildt"
|
|
|
|
|
class staff {
string code, name;
public:
staff() : code(0000), name("Unknown") {}
You have declared code as a string, but you are passing a value of 0, which is a null pointer.
|
|
|
|
|
|
Which is what the debugger would have shown you.
|
|
|
|
|
Is it possible to link a DLL in another DLL and call its functions?
How can we do that?
|
|
|
|
|
Yes, it's possible, and the same way that you access the functions of any DLL. But your question is not clear, what problem are you having.
|
|
|
|
|
Hi All,
I am having Three Radio Buttons in a Dialog Based Application. The Name of the Radio Buttons are IDC_RADIO1,IDC_RADIO2 and IDC_RADIO3.
I have Grouped the First Radio Button IDC_RADIO1. I have Disabled the First Radio Button which is Grouped.
Now When I change the selection of First Radio Button to Second Radio Button I am getting Assertion. I have google and found that this a Microsoft Issue which is mentioned as same in this link.
[Q114980: FIX: Disabled DDX Radio Button Causes Infinite Loop | KnowledgeBase Archive]
https://jeffpar.github.io/kbarchive/kb/114/Q114980/
Let me know if any solutions regarding this.
Thanks in Advance
|
|
|
|
|
janaswamy uday wrote: [Q114980: FIX: Disabled DDX Radio Button Causes Infinite Loop | KnowledgeBase Archive]
https://jeffpar.github.io/kbarchive/kb/114/Q114980/
Let me know if any solutions regarding this.
But it was very good written in the article you have mentioned!
Quote: RESOLUTION
To work around this problem, do one of the following:
- Arrange the group so that the first radio button is not disabled when any of
the other controls in the group are enabled.
-or-
- Call EnableWindow() to enable the radio button before DDX_Radio() is called
[for example, in DoDataExchange()].
-or-
- Write your own DDX_Radio() replacement, as shown in the sample code in the
"MORE INFORMATION" section, below.
STATUS
Microsoft has confirmed this to be a problem in Microsoft Foundation Classes,
versions 2.0 and 2.5. This problem was corrected in MFC version 3.0
MORE INFORMATION
One solution is to write your own DDX_Radio() replacement, which uses
::GetWindow() to iterate through all the controls on the dialog box until it
encounters one with style "WS_GROUP" or a handle of "NULL". The following sample
code is a substitute for DDX_Radio():
Sample Code
void AFXAPI DDX_MyRadio(CDataExchange* pDX, int nIDC, int& value)
{
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP);
ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) &
DLGC_RADIOBUTTON);
if( pDX->m_bSaveAndValidate )
value = -1;
int iButton = 0;
do
{
if( ::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) &
DLGC_RADIOBUTTON
)
{
if( pDX->m_bSaveAndValidate )
{
if( ::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0 )
{
ASSERT(value == -1);
value = iButton;
}
}
else
{
::SendMessage( hWndCtrl, BM_SETCHECK, (iButton == value), 0L
);
}
iButton++;
}
else
{
TRACE( "Warning: skipping non-radio button in group.\n" );
}
hWndCtrl = ::GetWindow( hWndCtrl, GW_HWNDNEXT );
} while(hWndCtrl!=NULL &&
!(GetWindowLong(hWndCtrl,GWL_STYLE)&WS_GROUP));
}
Remember to replace the following lines in your CDialog::DoDataExchange():
DDX_Radio(pDX, IDC_RADIO1, m_iRadio);
with:
DDX_MyRadio(pDX, IDC_RADIO1, m_iRadio);
|
|
|
|
|
Hi I have worked but this is not working.
My Requirement is to Disable the Group Radio button but still I am getting Assertion even after doing with
//{{AFX_DATA_MAP(CMyDialog)
DDX_MyRadio(pDX, IDC_RADIO1, m_iRadio);
//}}AFX_DATA_MAP
and the below Function
// DDX_MyRadio(), which is a modified DDX_Radio().
//
void AFXAPI DDX_MyRadio(CDataExchange* pDX, int nIDC, int& value)
// must be first in a group of auto radio buttons
{
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP);
ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) &
DLGC_RADIOBUTTON);
if( pDX->m_bSaveAndValidate )
value = -1; // value if none found
// walk all children in group
int iButton = 0;
do
{
if( ::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) &
DLGC_RADIOBUTTON
)
{
// control in group is a radio button
if( pDX->m_bSaveAndValidate )
{
if( ::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0 )
{
ASSERT(value == -1); // only set once
value = iButton;
}
}
else
{
// select button
::SendMessage( hWndCtrl, BM_SETCHECK, (iButton == value), 0L
);
}
iButton++;
}
else
{
TRACE( "Warning: skipping non-radio button in group.\n" );
}
hWndCtrl = ::GetWindow( hWndCtrl, GW_HWNDNEXT );
} while(hWndCtrl!=NULL &&
!(GetWindowLong(hWndCtrl,GWL_STYLE)&WS_GROUP));
}
Thanks
|
|
|
|
|
Then try to use another "workaround"!
|
|
|
|
|
Hi Victor,
Could you please let me know the possible solution. This is very Urgent requirement to me.
Help me out please.
Thanks
|
|
|
|
|
Try one of the other workarounds.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
There must be another reason for the assertion because you are very probable not using MFC 2.x shipped with the Microsoft C compiler versions 1.x:
Last Modified: 07-MAY-2001
-------------------------------------------------------------------------------
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), used with:
- Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5
- Microsoft Visual C++, 32-bit Editions, version 1.0
Quote: Now When I change the selection of First Radio Button to Second Radio Button I am getting Assertion How do you change the selection? Where does the assertion occur (MFC source file name, line, and in which function)?
Anyway, a radio button group is intended to have exactly one member checked. When activating a button, all other buttons will be unchecked. But a disabled button can't be checked or unchecked. If you need to disable a radio button, you must first ensure that it is not checked (usually by checking another button of the group).
The same applies when disabling a button in the template: It must not be set to checked.
|
|
|
|
|