很多做开发的人大概都会参考一些原代码,最近我一直被C、C++、VC++他们编译环境的
区别所困惑,比如:
1、想在C语言的程序中加入类,可是系统不认,不知如何解决?
2、C++的WINDOWS中的重画机制和VC++的ONDRAW()函数的机制有什么区别?等等
由此希望有高手指点一二!

解决方案 »

  1.   

    .......
    1、加入类的C叫C++,想在C中加入类,你无敌了,C中你可以用STRUCT来替代类的效果阿
    2、ONDRAW函数是MFC的对WM_PAINT消息的响应函数....
      

  2.   

    我的问题楼上的可能没听清:
    我想问的是
    1、编译系统是如何区分C还是C++的?我想不会仅仅是文件的后缀吧?
    2、VC++的重画是消息映射,C++中的消息映射机制和VC++中一样吗?有和区别?
      

  3.   

    当然不认了,c里面哪里有类库啊,你去哪里include啊
      

  4.   

    1。从来没有想过这样的问题。。寒,我想就是后缀吧!2。同样是处理消息WM_paint,只不过VC++把它封装了。
      

  5.   

    回楼上的:那么我将.C改为.cpp
    为什么仍然不能在文件中加入类呢?
      

  6.   

    不用什么区分吧,c有c的编译系统, c++有c++的,
      

  7.   

    回楼上:我一直都是全使用VC++作为编译系统。里面C、C++、VC++是在一起的
      

  8.   

    vc的编译程序是cl.exe,里面有c/c++编译器,还有链接器,会跟据你的程序后扩展明使用不同的编译方法,如.c用c方式编译,不认class关键字,.cpp/.cxx/.cc等用c++方式编译,支持c++语法。
      

  9.   

    DrMario wrote:
    > 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
      

  10.   

    其实在没有类这个概念的时候,c中的结构体正是起着这样的作用,它同样可以封装变量以及函数指针
    不过c++把面向对象的概念充分地发挥出来了c和c++的编译器是单纯的语言编译器,编译成机器语言
    而vc++则属于Windows下的开发平台,虽然他的语句级仍然是用c++的编译器,不过其中加入了复杂的win32运行平台机制.
      

  11.   

    那么编译系统是如何区分C还是C++的?========================================根据源文件的后缀名c还是CPP
      

  12.   

    我认为C++编译器是不区分C和C++的,它整合了C编译器然后再加上C++自己的语法!
    这样想对不对?