VC6.0中#inlude 一个头文件,这个头文件必须要 头文件名.cpp吗?
如果需要 #include "name.h"
是不是还要让VC有一个 name.cpp文件?
如果不必须那个name.cpp文件,怎么才能通过这个文件?
《C++大学教程》(第二版)331页7.10代理类书上的程序
----------------------------------------------------------------
// Fig. 7.10: implementation.h
// Header file for class Implementation
class Implementation {
public:
Implementation( int v ) { value = v; }
void setValue( int v ) {value = v; }
int getValue( ) const { return value; }
private:
int value;
};
// Fig. 7.10: interface.h
// Header file for interface.cpp
class Implementation; // forward class declaration
class Interface {
public:
Interface( int );
void setValue( int ); // same public interface as
int getValue( ) const; // class Implementation
private:
Implementation *ptr; // requires previous
// forward declaration
};
// Fig. 7.10: interface.cpp
// Definition of class Interface
#include "interface.h"
#include "implementation.h"
Interface::Interface( int v )
: ptr ( new Implementation( v ) ) { }
// call Implementation's setValue function
void Interface::setValue( int v ) { ptr->setValue( v ); }
// call Implementation's getValue function
int Interface::getValue( ) const { return ptr->getValue( ); }
// Fig. 7.10: fig07_10.cpp
// Hiding a class's private data with a proxy class.
#include <iostream.h>
#include "interface.h"
int main( )
{
Interface i( 5 );
cout << "Interface contains: " << i.getValue( )
<< " before setValue" << endl;
i.setValue( 10 );
cout << "Interface contains: " << i.getValue( )
<< " after setValue" << endl;
return 0;
}
----------------------------------------------------------------
怎么改过,才能在VC++6.0中运行?
我已经试过把这几个文件分开写,但打不开文件