Somebody claimed C++ is not necessary because he can use C to
implement all C++ features. What do you think?
Somebody claimed C++ is not necessary because he can use C to
implement all C++ features. What do you think?
of course that's true for some features of C++, but C++ has those features already and they're much easier to use this way.
in C, a virtual function table is a struct full of function pointers.
but you would be hard pressed to pull off templates with some kind of strange macro scenario. certainly inline functions closely resemble macros.
in short, tell your friend to STFU.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
I don't need C either, I just use a hexeditor, creating the exes myself. That way they become much smaller and I don't have to compile any code.
Everything can be done with a hexeditor, there's no need to learn C.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
How would you implement a function which takes a reference as
the argument in C? For example,
Code:void foo(SomeType&)
Perhaps like this:
Code:void __foo(SomeType* __tempname) { #define var (*__tempname) //.... #undef var } #define foo(a) __foo(&(a))
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
>Somebody claimed C++ is not necessary because he can use C to
>implement all C++ features. What do you think?
Or he doesn't know C++ or he is just stupid. Anyway, I'm very curious how he would implemented something like operator-overloading in C.
If this was the case, they'd implement the stl for c as well.
Any program you can make in c++, can be made in c, maybe that's what he means.
Sang-drax,
You are passing a pointer to SomeType as argument. You have to
de-referece the pointer in order to change the content of the passed in argument in the function. That's different. For example,
Code:void foo(int& v) { v++; } int main() { int a = 3; foo(a); cout << a; }
Shiro,
Member operator is nothing new but another form of member function. You could easily use a function in C to replace the operator.
Originally posted by CALVIN
Sang-drax,
You are passing a pointer to SomeType as argument. You have to
de-referece the pointer in order to change the content of the passed in argument in the function. That's different. For example,
What? Have you tried my example?
Code:void __foo(int* __tempname) { #define var (*__tempname) var++; #undef var } #define foo(a) __foo(&(a)) int main() { int a = 3; foo(a); printf("%d",a); return 0; }
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
var++ => (*__tempname)++. You're dereferencing the passed-in
pointer.
They could write a C++ interpreter/compiler in C, but apart from that why the would they want to? If you want to use a C++ feature use C++. Ask the person how they would implement something as simple a member functions in straight C. A C++ compiler resolves some of the C++ features at compile time. If you start implementing them using C you'll have to be careful or you start imposing runtime overhead, or not providing all the features that would be present in C++.Somebody claimed C++ is not necessary because he can use C to
implement all C++ features. What do you think?
If they mean then they can do anything in C that you can in C++, then this is true, but that's not implementing C++ in C (unless you're writing a compiler/interpreter). You may be able to replace operator overloading with functions, but then you're not really implementing a C++ feature, are you? Rather using an alternative technique.
Joe
And how do you think it's done internally using references?Originally posted by CALVIN
var++ => (*__tempname)++. You're dereferencing the passed-in
pointer.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
Sang- drax is right......the code produced for pointers is the same as for references....
The only difference is in the syntax of your code