|
Thanks for helping . Now it's working..It's my mistake.
|
|
|
|
|
|
We aim to please.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Rajesh R Subramanian wrote: We aim to please.
And pleasant it was.
Made my face turned into something that resembles a smile...
Also brought up the score for what it's worth...
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks for the vote, Roger. Glad you liked the pun.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
hi i have class
<br />
class abc<br />
{<br />
public:<br />
abc()<br />
{<br />
}<br />
void disp()<br />
{<br />
}<br />
};<br />
int main()<br />
{<br />
abc *c = 0;<br />
c->disp();<br />
return 0;<br />
}<br />
here for c is memory allocated. and can i access class methods from c.
|
|
|
|
|
manjunath k reddy wrote: here for c is memory allocated. and can i access class methods from c.
No..
BTW Why you want to do it?
Regards,
Sandip.
|
|
|
|
|
i have to nothing but only i wanted to know weather we can access class functions like this is it possible.
|
|
|
|
|
No. You didn't create any instance of the object and you try to access a NULL pointer, thus this will crash. You have to create an instance either with new or this way: MyClass a; .
Anyway, this is really the basics so before going any further, I suggest you read a good book on C++.
|
|
|
|
|
Just as a thought, if you need to access the member functions before creating an instance of the class you could define the function as static . That way if you needed to call the function, you could write abc::function();. Just realize that any member variables that the function needs will also have be declared static and at this point, you might as well not wrap the function in a class at all because it is sort of pointless. However, it is possible.
|
|
|
|
|
Even though it is not a standard way, such function calls are possible if the function disp() is not accessing any of the member variable of class abc. If it is accessing any member variable inside it, the execption will occur at that point.
But the point is, if we didnt access a member variable in a member function of the class, why make it member function...?Static or global is enough..
|
|
|
|
|
Naveen wrote: such function calls are possible if the function disp() is not accessing any of the member variable of class abc
You need to put one more requirement on that Naveen: it cannot be a virtual function since the virtual table goes with the instance of the object.
But, as you said, it serves no point making it a member function even though it will compile and run. It would be extremely poor design.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: it cannot be a virtual function since the virtual table goes with the instance of the object
Ya you are correct. thanks for pointing...
|
|
|
|
|
manjunath k reddy wrote:
class abc
{
public:
abc()
{
}
void disp()
{
}
};
int main()
{
abc *c = 0;
c->disp();
return 0;
} here for c is memory allocated. and can i access class methods from c.
No!
There is no memory allocated for 'c'. The variable 'c' is a pointer to an object of 'abc'-type and you've assigned NULL to that pointer.
If you will try to execute the code above you will get a runtime error saying "access violation" in your face.
The question you're asking, for the second time(!) even though you've already got an answer, makes no sense.
It suggests that you have no clue about the concept of object oriented analysis/design/programming.
Consider the following analogy:
- "I want to change tyres on my car. How do I do that?"
- "What kind of car do you have?"
- "I don't have a car."
- "????"
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
100% you will be get error wheres your memory allocated for c in this code you have a pointer without any instance of object and you want to use of a null pointer?
|
|
|
|
|
|
You've posted a similar question before and my answer is similar to the already given one:
You really need a good C++ tutorial.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Does anyone know how I got the oleauto.h version that only defined this function as taking 3 parameters?
STDAPI VarBstrCmp(BSTR bstrLeft, BSTR bstrRight, LCID lcid);
I also got errors for...
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlbase.h(4497) : error C2660: 'VarCmp' : function does not take 3 parameters
I recently had my machine rebuild and have installed VS6 & SP6.
modified on Tuesday, October 14, 2008 1:49 AM
|
|
|
|
|
lee23 wrote: Does anyone know how I got the oleauto.h version that only defined this function as taking 3 parameters?
STDAPI VarBstrCmp(BSTR bstrLeft, BSTR bstrRight, LCID lcid);
Google knows: http://www.codeproject.com/script/Forums/View.aspx?fid=1857&msg=49323[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
This article you pointed me to indicates this is pre service pack 3 of Visual Studio. I have installed SP6. I wouldn't want to fix the problem by modifying the file but rather find out why I've got those files instead of the correct ones I need.
|
|
|
|
|
lee23 wrote: I have installed SP6. I wouldn't want to fix the problem by modifying the file but rather find out why I've got those files instead of the correct ones I need
That's good. Possibly you have to change the search order of Visual Studio include directories.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi all,
I need your help in my code I got from the gsoap article of Dr. Luigi here is his code:
CString CMyCurrencyConvertor::GetSoapError()
{
struct soap *pSoap = m_pCurrencyConvertor->soap;
CString sError;
if (soap_check_state(pSoap ))
sError.Format("Error: soap struct not initialized\n");
else
{
if (pSoap->error)
{
const char *pFaultCode, *pFaultSubCode = NULL, *pFalutString,
**iFaultCode;
iFaultCode = soap_faultcode(pSoap );
if (!*iFaultCode)
soap_set_fault(pSoap );
pFaultCode = *iFaultCode;
if (pSoap ->version == 2)
pFaultSubCode = *soap_faultsubcode(pSoap );
pFalutString = *soap_faultstring(pSoap );
iFaultCode = soap_faultdetail(pSoap );
sError.Format("%s%d fault: %s [%s]\"%s\"Detail: %s",
pSoap->version ? "SOAP 1." :\
"Error ", pSoap->version ? (int)pSoap->version : pSoap->error,
pFaultCode, \
pFaultSubCode ? pFaultSubCode : "no subcode",
pFalutString ? pFalutString : "[no reason]", \
iFaultCode && *iFaultCode ? *iFaultCode : "[no detail]");
}
}
return sError;
}
Now as per his advise is used MultiBytetoWideChar as the sError being returned is in japanese/chinese.
I modified his code into this:
sError.Format(_T("%s%d fault: %s [%s]\"%s\"Detail: %s"),
pSoap->version ? "SOAP 1." :\
"Error ", pSoap->version ? (int)pSoap->version : pSoap->error,
pFaultCode, \
pFaultSubCode ? pFaultSubCode : "no subcode",
pFalutString ? pFalutString : "[no reason]", \
iFaultCode && *iFaultCode ? *iFaultCode : "[no detail]");
MultiByteToWideChar( CP_ACP, 0, CT2A(sError),
strlen(CT2A(sError))+1, wszFaultString,
sizeof(wszFaultString)/sizeof(wszFaultString[0]) );
Now my problem is that once it is converted instead of the words i am expecting i get question marks example is
fault: ????? but it should be fault: host not found.
What should I do?
Thanks,
Jayjay
|
|
|
|
|
You have a few diagnostic tools...
Try putting wszFaultString,su into the watch window to see the wide string. (I assuming you are debugging this line by line? If not, don't come back until you have)
Also, you can view each unicode character individually, and see if the characters are being converted accurately (compare contrast with charmap) and visual studio is just having japanese font rendering problems, or even your app is displaying the text in a font that is missing those characters...
You're not checking the response from MultiByteToWideChar - are you sure it is succeeding?
What's with the CTO2A macro? If you're doing an explicit conversion, shouldn't you handle it yourself? That way you can see the intermediate results...
Good luck,
Iain.
|
|
|
|
|
So I am still relatively new to coding, so bear with me if I'm missing something obvious. I am trying to write software using the GP3 board by AWC with Visual Studio 2008. I received a package with the .h, .lib, and .dll files with it. I include them all in the same directory as my project, and tell it to include the .h file in the preprocessor. But when it loads the header file, I get tons of errors...including alot of syntax. Here is the basic layout of the header file.
#ifndef __GP3_HEADER_AWC
#define __GP3_HEADER_AWC
extern "C" {
__declspec(dllimport) HANDLE __stdcall GP3OpenCom(int port);
__declspec(dllimport) void __stdcall GP3CloseCom(HANDLE);
__declspec(dllimport) void __stdcall GP3SetLED(HANDLE h,BOOL state);
__declspec(dllimport) void __stdcall GP3SetTRIS(HANDLE h,int tris);
} #endif
Is this header file messed up, or am I just not doing something else right?
|
|
|
|
|
gargeug wrote: and tell it to include the .h file in the preprocessor
What do you mean by that?
You should use
#include "theheader.h"
in your source modules that need to use anything declared in the .h file.
gargeug wrote: I received a package with the .h, .lib, and .dll files with it. I include them all in the same directory as my project
The DLL should be in the same folder as your app's EXE file, or
anywhere else in the DLL search order[^].
You'll also need to add the .lib file to the list of import libraries
in your project settings. See
Project properties/Configuration properties/Linker/Input/Additional Dependencies
(.lib file names are separated by spaces)
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|