|
When we say C++ supports OOP, it also means that the C++ compiler understands and compiles the OOP syntax.
Since C does not understand OOP, you have to write all the code yourself.
For example, OOP call the constructor when an object is created.
This is nothing but calling a function just after allocating memory for a data type.
In C++ you simply have to write a constructor according to the rules of a constructor.
But in C, you have to write a function and call that in code.
|
|
|
|
|
You don't need an object-oriented language to do object-oriented programming. Going back to C once after many years of C++, I noticed I was using typedefs more effecively, as a substitute for "class". You can also use static members in C to simulate the private members of a C++ class.
The Decorator design pattern (http://en.wikipedia.org/wiki/Decorator_pattern ) can be used to add inheritance to languages that don't have it, like C.
The basic idea is that the "virtual" methods of each "class" (typedef'd struct) have a function pointer that can be set to a function in a parent class. If the pointer is non-NULL, it's called to simulate inheritance.
|
|
|
|
|
Alan Balkany wrote: You can also use static members in C to simulate the private members of a C++
class.
Not sure what that statement means.
Static in C is not equivalent to class members. On can use a struct in C to contain member variables.
If one wants to mimic 'private' (which I think is overkill) then one can use a struct whose scope is limited to the C file and which is allocated when a more globally visible struct (different one) is allocated.
|
|
|
|
|
I meant static functions in C aren't visible outside the file they're declared in, which can be used to simulate private functions in C++.
|
|
|
|
|
While you've got plenty of useful responses already I'd like to add the fact that early C++ compilers were in fact pre-compilers that translated C++ code into C code. However, these precompilers had a very hard time when it came to templates, and therefore these early C++ 'front-ends' were not able to support the full template syntax.
In view of your question, since Templates are not a neccessary concept for OOP, C can clearly be used for OOP. It is just, as others have already pointed out, not very well suited to it.
|
|
|
|
|
hi,
how can i implement a dll for connecting the browser through proxy server in vc++
|
|
|
|
|
This question is not very clear. Why do you think you need a DLL to achieve this, and exactly what problem are you trying to solve? Any half decent browser will be able to handle communication through a proxy transparently.
|
|
|
|
|
Hi all. How can I know for sure if the user have pressed TAB or SHIFT + TAB in a MDI application ? I read something vague on internet, nothing clear. Thank you.
|
|
|
|
|
Can GetKeyState[^] or GetAsyncKeyState[^] help?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I solved with GetAsyncKeyState Function.Thank you.
|
|
|
|
|
Yourwelcome.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I use gsoap to create a proxy class to call my web service's interfaces, but now the methods return error 4 and 12.
I debug these errors and google that error for solution, but I cannot find. Can anyone tell me why the methods return these error?
modified 2-Apr-12 12:44pm.
|
|
|
|
|
Which methods return the error codes? Please show an extract of your code and the values of your input parameters for the instances that fail.
|
|
|
|
|
A method defined in the web service that will return a structure including an array memebers.
|
|
|
|
|
yu-jian wrote: A method defined in the web service that will return a structure including an array memebers.
What exactly does that tell us?
|
|
|
|
|
If the methods are in your code, you should know why they are returning 4 and 12.
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
|
Hi Developers,
I want to show the text "Add Photo" in a picture control, initially ( if no photo has attached to it ).
Can anyone told me about it.
Thanks in Advance.
Amrit Agrawal
|
|
|
|
|
The simplest thing that comes to my mind is: make a picture that shows your text and place that into your picture control (loaded from resource e.g.). Wouldn't that work for you?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
The first thing to explain is what you mean by a picture control. Is this something you created yourself, a third party class or an MFC class?
|
|
|
|
|
Yes this is a control created by myself.
|
|
|
|
|
Amrit Agr wrote: Yes this is a control created by myself.
So how do you expect us to debug it for you without any idea of how it works?
|
|
|
|
|
DrawText[^]?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
1. Respond to WM_SETTEXT in your control's WindowProcedure, create copy of string
2. When called upon to redraw, the control should check to see if an image has been assigned
3. If so, display image
- If not, use DrawText or TextOut to display the text received via the WM_SETTEXT message.
|
|
|
|
|
I have a strange problem : I succesfully download a file from a server with follow code :
BOOL CUpdateThread::DownloadFile(CString sAddress, CStringArray& saResult)
{
CString sTemp;
BOOL bRet = FALSE;
CInternetSession ISession;
CInternetFile* pIFile = NULL;
try
{
pIFile = (CInternetFile*)ISession.OpenURL(sAddress);
while(pIFile->ReadString(sTemp))saResult.Add(sTemp);
bRet = TRUE;
}
catch(CInternetException* pInternetException)
{
pInternetException->GetErrorMessage(m_pMessage->GetBuffer(255),255);
m_pMessage->ReleaseBuffer();
pInternetException->Delete();
}
catch(CException* pException)
{
pException->GetErrorMessage(m_pMessage->GetBuffer(255),255);
m_pMessage->ReleaseBuffer();
pException->Delete();
}
if(pIFile)
{
pIFile->Close();
delete pIFile;
}
ISession.Close();
return bRet;
}
let say that with this code, I download from an server a text file, test.txt ( a list of words, nothing special ). I change the content of the text file to server, I download again the same text file, test.txt, but content is the same( doesn't have changes ). I stop the application, start again, and if I download again the text file, test.txt, the contain is now changed ... why ?
|
|
|
|