主函数:
...
#inculde <"stdAfx.h">
...
int miain(....)
{
  TTest Test; // TTest 在 stdAfx.h 定义的
  Test.outInt(123);
  return 0;
}// 头文件 stdAfx.h 的TTest类
class TTest{
publich:
   void outInt(int i);
};
void TTest::outInt(int i){ cout <<i <<endl ; } //会出错, 若在class TTest{...},则不会问题是:如outInt 在class TTest ...{...} 实现是正常运行的,若有成员函灵数实现会出错,
就上面的void TTest::outInt(int i){ cout <<i <<endl ; } 请问大家,这是不是语法错误,或是...,,要怎么解决,请大家帮忙

解决方案 »

  1.   

    如果,把TTest 跟main放在同一个文件,
    不论方法outInt是在class TTest实现,
    还是用void TTest::outInt(int i){...}实现,都不会错的
      

  2.   

    在stdafx.cpp里面写
    void TTest::outInt(int i){ cout <<i <<endl ; } //会出错, 若在class TTest{...},则
      

  3.   

    函数定义void TTest::outInt(int i){ cout <<i <<endl ; } 
    写到cpp文件中
      

  4.   

    一般是这样的
    准备两个同名的文件  类名.h 和 类名.cpp
    头文件中放类的定义, cpp中写实现方法
    这样比较规范
    像void TTest::outInt(int i){ cout <<i <<endl ; }写到cpp中比较好
    如果要写在头文件中,就是用内联函数的形式,也是可以的
    要是写在类结构的外面就只能定义函数