Like you have done with multiple preprocessor #if statements.
Using weird preprocessor macros to create a loop.
Initialising by code using a loop.
Writing a helper program that creates a file with the relevant code lines that can then be included in a source file or even linked when declaring the struct as extern. The helper program must then be executed by the make file (or a corresponding custom build option when using an IDE) before compiling.
in the above code if i assign a string literal to a const char*
const string *name = "tarun";
it prints the string but the same with string gives error that
cannot convert ‘const char’ to ‘const string
so it means any string literal is a const char (which i think is a rvalue),
but it is a collection of characters, so how is it a char ? and if it is a char then why it is called string literal ?
...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
constchar *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.
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:
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 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.
But it was very good written in the article you have mentioned!
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.
Call EnableWindow() to enable the radio button before DDX_Radio() is called
[for example, in DoDataExchange()].
Write your own DDX_Radio() replacement, as shown in the sample code in the
"MORE INFORMATION" section, below.
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
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():
// 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) &
if( pDX->m_bSaveAndValidate )
value = -1; // value if none found// walk all children in groupint iButton = 0;
if( ::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) &
// control in group is a radio buttonif( pDX->m_bSaveAndValidate )
if( ::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0 )
ASSERT(value == -1); // only set oncevalue = iButton;
// select button
::SendMessage( hWndCtrl, BM_SETCHECK, (iButton == value), 0L
TRACE( "Warning: skipping non-radio button in group.\n" );
hWndCtrl = ::GetWindow( hWndCtrl, GW_HWNDNEXT );
} while(hWndCtrl!=NULL &&
Remember to replace the following lines in your CDialog::DoDataExchange():