怎样实现模板的声明实现分离?该怎么解决
怎样实现模板的声明实现分离?
try.h
--------------------------
#ifndef TRY_H
#define TRY_H
template <typename T>
class Try
{
public:
Try(T val);
~Try();
T A(int val);
private:
T value;
};
try.cpp
---------------------
#include "try.cpp "
#endif
#include "try.h "
#include <iostream>
template <typename T>
Try::Try(T val):value(val)
{
std::cout < < "Created Try() " < < val < < std::endl;
}
template <typename T>
Try::~Try()
{
std::cout < < "Destroyed ~Try() " < < std::endl;
}
template <typename T>
T Try::A(T value)
{
std::cout < < "A() " < < value < < std::endl;
}
------解决方案--------------------
需编译器支持export关键字,搜索export,看资料的说明
------解决方案--------------------
自己写编译器支持,因为目前常见的编译器都不支持.
------解决方案--------------------
暂时不要幻想了。参考《Exceptional C++ Style》的第9条和第10条。
------解决方案--------------------
在*.h文件后面去#include *.cpp吧
很少有编译器支持分离编译模式.
------解决方案--------------------
不要在这个问题上浪费时间了。
------解决方案--------------------
自己写编译器支持,因为目前常见的编译器都不支持.
------解决方案--------------------
把你的.cpp文件后缀改成别的就可以,不要用cpp。VC6是支持的
try.h
--------------------------
#ifndef TRY_H
#define TRY_H
template <typename T>
class Try
{
public:
Try(T val);
~Try();
T A(int val);
private:
T value;
};
try.cpp
---------------------
#include "try.cpp "
#endif
#include "try.h "
#include <iostream>
template <typename T>
Try::Try(T val):value(val)
{
std::cout < < "Created Try() " < < val < < std::endl;
}
template <typename T>
Try::~Try()
{
std::cout < < "Destroyed ~Try() " < < std::endl;
}
template <typename T>
T Try::A(T value)
{
std::cout < < "A() " < < value < < std::endl;
}
------解决方案--------------------
需编译器支持export关键字,搜索export,看资料的说明
------解决方案--------------------
自己写编译器支持,因为目前常见的编译器都不支持.
------解决方案--------------------
暂时不要幻想了。参考《Exceptional C++ Style》的第9条和第10条。
------解决方案--------------------
在*.h文件后面去#include *.cpp吧
很少有编译器支持分离编译模式.
------解决方案--------------------
不要在这个问题上浪费时间了。
------解决方案--------------------
自己写编译器支持,因为目前常见的编译器都不支持.
------解决方案--------------------
把你的.cpp文件后缀改成别的就可以,不要用cpp。VC6是支持的