|
Hi Maxwell!!
Probably you forget to increment value of "i" before return like i = i + 1; .
Why you are having char* argument as you are returning char*?
Regards,
Suman
|
|
|
|
|
rp_suman wrote: Probably you forget to increment value of "i" before return like i = i + 1;.
Yes I forgot. Sorry!
rp_suman wrote: Why you are having char* argument as you are returning char*?
To return the original address for later use. As:
char* Test(char* str)
{
static int i = 1;
sprintf(str, "%d.", i++);
return str;
}
char sBuf[10] = {0};
int v = 0;
for( ; v < 3; v++) {
printf(Test(sBuf));
printf("\n");
}
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: To return the original address for later use.
That's nice..
Thanks & Regards,
Suman
|
|
|
|
|
Hi all,
I have a class and one of it has a function as follows.
void CMsgRecorder::SetGroupState(char chState)
{
}
defining as follows,
class CMsgRecorder
{
public:
void SetGroupState(char chState);
}
Other class has following function.
void CRfSvrDriver::ShowInfo()
{
}
It's also define as public function in CRfSvrDriver class. How can I call SetGroupState() from the ShowInfo() which are in two classes.
Help really appreciate
I appreciate your help all the time...
Eranga
|
|
|
|
|
use inheritance.
class CMsgRecorder
{
public:
void SetGroupState(char chState)
{
do-something;
}
};
class CRfSvrDriver : public CMsgRecorder
{
public:
void ShowInfo()
{
SetGroupState();//calls the base function CMsgRecorder::SetGroupState
}
};
|
|
|
|
|
Yes I do, but the question is this. I already use one class there as follows.
class CRfSvrDriver :
public CCmdDriver
How can I used another class, how to separate those two
I appreciate your help all the time...
Eranga
|
|
|
|
|
then why don't you try this
class CRfSvrDriver :public CCmdDriver,public MsgRecorder
OR
u want to maintain two separate version of the class CRfSvrDriver ?
|
|
|
|
|
Ok, I can separate by a comma and do it. But then I comes with a constructor issue. I can't change my constructor now.
So I change my plan, simply used a pointer to the other class as follows. Include the CMsgRecorder header file in the ShowInfo header file.
void CRfSvrDriver::ShowInfo(CMsgRecorder* msgRec)
{
msgRec->SetGroupState('R');
}
But it gives a compile error.
error LNK2019: unresolved external symbol "public: void __thiscall CMsgRecorder::SetGroupState(char)"
(?SetGroupState@CMsgRecorder@@QAEXD@Z) referenced in function "public: int __thiscall
CRfSvrDriver::ProcessCommand(class ATL::CStringT<char,class strtraitmfc_dll<char,class="" atl::chtraitscrt<char=""> >
>,unsigned int,class CMsgRecorder *)"
(?ProcessCommand@CRfSvrDriver@@QAEHV?$CStringT@DV?$StrTraitMFC_DLL@DV?$
ChTraitsCRT@D@ATL@@@@@ATL@@IPAVCMsgRecorder@@@Z)
</char,class>
I hope it is linker error, but all functions are declared correctly. You have any suggestion for me on this.
I appreciate your help all the time...
Eranga
|
|
|
|
|
the linker cannot find the definition of SetGroupState that is the problem. whether u declared SetGroupState as a static function? or not defined it.
And another thing i don't think the method u opted is a good programming practice. Inheritance is the good method in such situations.
|
|
|
|
|
Ok pal. Thanks.
Actually I missed one thing there. Those two classes are in two projects. I think that is why there is a linker error. What I can do now.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Then make a DLL of the project that contains class CMsgRecorder. Then include .h file of the class and lib file in your new project. Then compile it. ie's it.
|
|
|
|
|
I'll see, because working with DLLs are really new work for me.
I appreciate your help all the time...
Eranga
|
|
|
|
|
class CMsgRecorder
{
public:
void SetGroupState(char chState)
{
do-something;
}
};
Now you can use multi-one inheritance like this
class CRfSvrDriver : public CMsgRecorder,public CCmdDriver
{
public:
void ShowInfo()
{
SetGroupState();//calls the base function CMsgRecorder::SetGroupState
}
};
|
|
|
|
|
Hello everyone,
As far as I know, C function does not throw exception.
But Bjarne said in his book, section 14.8 Exception and Efficiency,
--------------------
In particular, an implementation knows that only a few standard C library functions (such as atexit() and qsort()) can throw exceptions, and it can take advantage of that fact to generate better code.
--------------------
What did he mean? C function could really throw exception? What exception -- C++ exception or structured exception?
thanks in advance,
George
|
|
|
|
|
Why don't you read the next paragraph?!
Maxwell Chen
|
|
|
|
|
I read all the section, Maxwell!
Could you show your point to my original question please?
regards,
George
|
|
|
|
|
"... it might have been converted ..."
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
The whole sentence is "it might have been converted to use the C++ operator new". How could C code use C++ operator new?
regards,
George
|
|
|
|
|
Remember that the scope now is in C++. Stroustrup's book is a C++ book. And "C Library" is a subset of C++. Even though the function names of C Runtime Library are the same, the internal may be different.
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I have got your point.
regards,
George
|
|
|
|
|
Hello everyone,
On Windows, when we allocate large amount of memory, new will call VirtualAlloc directly, other than call HeapAlloc then through HeapAlloc call VirtualAlloc indirectly?
Anyone to clarify this?
thanks in advance,
George
|
|
|
|
|
dear all
how to solve the following problem: after compilation:
psofile.cpp(150) : error C2109: subscript requires array or pointer type
thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
li zhiyuan wrote: how to solve the following problem ... psofile.cpp(150) : error C2109: subscript requires array or pointer type
by modifying whatever is in line 150 until it is correct.
my guess is whatever is to the left of an open square bracket should be but isn't an array or a pointer.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
li zhiyuan wrote: how to solve the following problem: after compilation:
psofile.cpp(150) : error C2109: subscript requires array or pointer type
This deserves a place in the Top 5 list of idiotic posts.
|
|
|
|
|
I am trying to print (text) fields onto a form. so I need to specify to my print fumction the exact x and y coordinates. The following code shows what I tried to do. I specify the coordinates but it prints a bit off not falling into the boxes of the from. I tried accounting for printer margins and still cannot get it to properly print. What am doing wrong ? For that matter is there a better way ?
Here are parts of relevant code.
omap = pDC->SetMapMode (MM_TEXT);
sx = pDC->GetDeviceCaps (LOGPIXELSX); // x axis pixels per inch
yx = pDC->GetDeviceCaps (LOGPIXELSY); // y axis pixels per inch
xmargin = pDC->GetDeviceCaps (112); // Left margin
ymargin = pDC->GetDeviceCaps (113); // Top margin
r_font.CreateFont (-Size, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New");
SelectFont (&r_font);
// to move half inch in and half inch down xpos would be sx/2
// and yx/2 (not accounting for printing margins). If accounting
// then factor in xmargin and ymargin.
TextOut (xpos, ypos, str, sz);
Thanks
I am using Visual C++ 5.0
|
|
|
|