|
Hello All,
Can anyone tell me that what is the different when declare function like
const char* f();
and
char* const f();
I would like to know what does this two function signature means.
Thanks!
Nachi
|
|
|
|
|
easy, the second don't exist ! lol
in fact, you might want to say
const char* f();
char* f const();
that's simple. the first one returns a const char* when the second one returns a simple char*.
What does the second const mean, you'll ask me !? In fact, that is used in object programming, when you read values in an object, where you don't alterate that object... In brief, it means that you don't modify the members of your objet... you don't need this in pure C so...
see you
TOXCCT >>> GEII power
|
|
|
|
|
Ummm,
You said the second one
char* const f();
does not exist, but if I write this in Visual C++, the compiler does not complain. Also, for the first one, I can actualy return something which is not a const, eg,
const int f()
{
int i = 10;
return i;
}
and it also works in Visual C++ too. And would you mind to tell me why's that?
Thank you very much!
Nachi
|
|
|
|
|
Stop playing silly games in here, returning a const value doesn't make any sense!
Don't try it, just do it!
|
|
|
|
|
Hello,
You are right, I know that it does not make any sense, but I still don't know what is this,
int const f();
even thought I never use it in my programming experience. But in some C++ test, people ask something about this, and what I know and what I have used is only something like this,
void f(const int);
or
void f(int) const;
and these both make sense to me, but not
int const f();
therefore, the's why I would like to know whether this signature make sense to any of you.
But anyway, thank you for all your suggestio!
Nachi
|
|
|
|
|
Did this not help?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Sorry, it doesn't really help, I know how to use a constant data in a program, but I have some confussion when using in the definition of functions
Thanks!
Nachi
|
|
|
|
|
So doesn't it make more sense to continue that thread rather than creating a new one of the same topic?
In any case, MSDN has this to say about const :
When modifying a data declaration, the const keyword specifies that the object or variable is not modifiable. When following a member function's parameter list, the const keyword specifies that the function doesn't modify the object for which it is invoked.
With C++, const is often used in place of the #define preprocessor directive. Values defined with const are subject to type checking, and can be used in place of constant expressions.
When const is used with pointers, it specifies that the pointer cannot be modified after initialization; the pointer is protected from modification thereafter.
So, const char *cpch means that the object pointed to by the pointer is const. And, char *const pchc means that the value of the pointer — the actual address stored in the pointer — is const.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
const char* means "pointer to a constant char " - you cannot change the value of the char that is pointed to, but you can change the pointer to point at some other char .
char* const means "constant pointer to a char " - you can change the value of the char pointed to, but you cannot change the pointer to point a some other char .
And const char* const means a combination of the two.
Example code:
char c = 'c';
char d = 'd';
const char* p1 = &c;
char* const p2 = &c;
*p1 = 'x';
p1 = &d;
*p2 = 'z';
p2 = &d;
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Laugh it up, fuzzball.
|
|
|
|
|
I've used the sample code from the posting about 'using alxBase classes with dbf files' and I can't get the table to be recognized by foxpro. does anyone have any knowledge of how to use an api to create a foxpro (or dbase) table through code and specify the correct header info. Following is what I wrote to the author of the code, but just in case, I'm looking for some help as quickly as possible.
this is my fault. I don't understand how to modify the header info correctly to specify the table type correctly (along with the other fields). I create a table, and using the sample viewer demo that came with this project, I can see the data in the table, even though a couple of the column header names are messed up. But when I try to open up the table in VFP I get a message telling me to specify the code page it was created in. I tried to modify the header info, but I can't seem to get this to work right. Can you please help?
If it's broken, I probably did it
bdiamond
|
|
|
|
|
I'm silly guy , I've just changed the system language and it works.
In that way, all the controls can show text in russian.
.... I'm furious!.
Bye.
Demian.
|
|
|
|
|
Is it possible to have a class instantiate a second class in it's constructor by passing a "this" pointer to the second class? And then have the second class hold and use the pointer to the first class? I believe this is causing a circular dependency and I don't know how to get around it. In other words, class A includes a header file for class B. Class A then instantiates a new class B in its constructor like this: B* classB = new B(this). Class B then needs to include the header file for class A so that it can hold a pointer to it and call functions on it via this pointer. I've tried using forward declarations, but I get an error saying that class so-and-so is undefined. Is there any way to do this or do I need to rethink my code?
|
|
|
|
|
yes.
bisquic wrote:
class A includes a header file for class B.
no, never include B in A ...
do something like :
class B;
class A
{
A( B* pPointerToClassB );
B* m_pPointerToClassB;
}
#include "b.h"
A::A( B* pPointerToClassB ) : m_pPointerToClassB( pPointerToClassB )
{
}
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Thanks for the quick response. I'm a bit confused though. You said never to include B in A, but in the second code example you are doing just that, no? Also, let me clarify, I want A to create a class B, and then for B to be able to hold a pointer back to A. So in the end, they should both be able to call functions on each other.
|
|
|
|
|
You dont need to include B in A, just declared B as being a class in order to let A to hold a pointer member of type B
#include b sould be replaced by #include a
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
yes, but I don't include it in the header file of class A.
to continue with your clarifications ...
class B;
class A
{
A();
B* m_pB;
}
#include "b.h"
A::A( )
{
m_pB = new B( this );
}
class A;
class B
{
B( A* pA );
A* m_pA;
};
#include "a.h"
B::B( A* pA ) : m_pA( pA )
{
}
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Ah ha! That did the trick. Thanks so much! I've been trying to get this to work for hours now. So the trick is to use a forward declaration in the header and then include the other header in the implementation. Not quite sure what the difference is there, but I sure am happy it works. Thanks again, you just cleared up a big headache for me
|
|
|
|
|
I'm pretty sure that using this in a constructor is asking for trouble (in the same way it's asking for trouble to use virtual functions belonging to the class in it's constructor).
What happens when class B chucks your (A) this pointer to some other object that already exists, and then the A::A() constructor throws an exception? Your A object doesn't exist, but you have a pointer to where it's partially constructed remains might be, which you'll almost certainly try to use
Ian Darling
"The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell
|
|
|
|
|
Hi everybody.
I am written an application that support text in russian. How can I make the edit box shows text in russian when the user write in that language?.
I want unicode support for every control, but I don't know how to do that.
Thank you in advance.
Regards.
Demian.
|
|
|
|
|
switch to Unicode in your project settings.
there are APIs for both ansi and unicode, and e.g. SetWindowText is defined as SetWindowTextA with ansi and SetWindowTextW with unicode!
Don't try it, just do it!
|
|
|
|
|
in the projectsettings->C/C++ tab add _UNICODE,UNICODE to other defines.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
in the projectsettings->C/C++ tab add _UNICODE,UNICODE to other defines.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
i have to show a dynamic graph layout, and it must be interactive and rearranged everytime an user insert or delete a determinate node... The application may be similar to Touchgraph (www.touchgraph.com) or kaon (http://kaon.semanticweb.org/demos). The problem is that i must create the application with some C++ library instead that java. Do you some idea? Do you know some library, some examples or some free C++ sourcecode witche may help me???
Sorry for my english, Bye, thanks!
|
|
|
|
|
for your requirement GDI/GDI+ will suffice. checkout how to draw line, circles etc for your graph requirement.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Hi, I have a set of radio box in my a group box.
I could not set any of the radio buttons.
the member variable is of type int.
I try to set it using m_membervariable = 0 and so on.
Thanks,
Deepak Samuel.
|
|
|
|