很多做开发的人大概都会参考一些原代码,最近我一直被C、C++、VC++他们编译环境的
区别所困惑,比如:
1、想在C语言的程序中加入类,可是系统不认,不知如何解决?
2、C++的WINDOWS中的重画机制和VC++的ONDRAW()函数的机制有什么区别?等等
由此希望有高手指点一二!
区别所困惑,比如:
1、想在C语言的程序中加入类,可是系统不认,不知如何解决?
2、C++的WINDOWS中的重画机制和VC++的ONDRAW()函数的机制有什么区别?等等
由此希望有高手指点一二!
1、加入类的C叫C++,想在C中加入类,你无敌了,C中你可以用STRUCT来替代类的效果阿
2、ONDRAW函数是MFC的对WM_PAINT消息的响应函数....
我想问的是
1、编译系统是如何区分C还是C++的?我想不会仅仅是文件的后缀吧?
2、VC++的重画是消息映射,C++中的消息映射机制和VC++中一样吗?有和区别?
为什么仍然不能在文件中加入类呢?
> So VC++ thinks it's looking for "C++ functions" as opposed to "C
> functions", and naming my main() function file with .c solved my
> problem. So my question is this... what makes, or does NOT make, a
> function a C++ function? What is it about those function definitions
> that caused VC++ to believe they were not C++ functions, but rather C
> functions? The way I was "raised" learning C++ is that any C
> function is a C++ function, just without the extended functionality
> C++ lends (inheritance, polymorphism, classes, etc. etc.).I'll answer here but in general questions like this better belong to some VC
newsgroup (public.vc.language could be a good candidate)The thing to realise is that C and C++ are completely different languages
compiled with different compilers. It is true that syntactically and
semantically C is almost a subset of C++ but this has nothing to do with the
fact that they are different languages. The thing to realize is that when
you compile C++ code *all* functions are C++ functions and when you compile
with C *all* functions are C functions. What probably confuses you is that
because the languages are so similar you can take a chunk of C source code
compile it with C++ compiler and it will compile and work ok. However, this
code is still compiled as C++. After all Java is also very similar to C so
you can compile some C code using Java compiler. In this case it wouldn't
suprise you that the resulting code would be Java code, right? ;-)The final thing is that most C++ compiler products such as VC come bundled
with C compiler too. When you compile a given source file the product tries
to be "smart" and guess what language this source file was written. On
windows the convention is that .c means that the file is written in C and
must be compiled using C compiler. .cpp, .cxx and few others are assumed to
be C++. When you changed extension of your files to .c you effectively told
VC that all your code is written in C and this is how it is going to be
compiled. Now you don't have C++ at all. ;-)The extern "C" directive I wrote about earlier works on another plane. It
allows *linkage* of C++ and C code and mix and match them in the same
application.--
Eugene
不过c++把面向对象的概念充分地发挥出来了c和c++的编译器是单纯的语言编译器,编译成机器语言
而vc++则属于Windows下的开发平台,虽然他的语句级仍然是用c++的编译器,不过其中加入了复杂的win32运行平台机制.
这样想对不对?