在VC6.0中是否无法编译通过普通类中的模板成员函数,详见内:
代码:
1、test.h
#ifndef _TEST_H_
#define _TEST_H_
class A
{
public:
A(){};
~A(){};
static void print(int i);
};
class B
{
public:
B(){};
~B(){};
static void print(int i);
};
class C
{
public:
C(){};
~C(){};
template< class T >
void test(int num)
{
T::print(num);
};
};
template< class T >
void test(int num)
{
T::print(num);
};
#endif
2、test.cpp
#include <stdio.h>
#include "test.h"
void A::print(int i)
{
printf("A::i = %d\n", i);
}
void B::print(int i)
{
printf("B::i = %d\n", i);
}
void main()
{
C p;
p.test<A>(2); //在VC下有编译错误,用g++再linux下可以正常编译
p.test<B>(2); //在VC下有编译错误,用g++再linux下可以正常编译
}
在VC6.0下编译错误:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
E:\tmp\test.cpp(19) : error C2275: 'A' : illegal use of this type as an expression
e:\tmp\test.h(5) : see declaration of 'A'
E:\tmp\test.cpp(20) : error C2275: 'B' : illegal use of this type as an expression
e:\tmp\test.h(15) : see declaration of 'B'
Error executing cl.exe.
test.exe - 2 error(s), 0 warning(s)
1、test.h
#ifndef _TEST_H_
#define _TEST_H_
class A
{
public:
A(){};
~A(){};
static void print(int i);
};
class B
{
public:
B(){};
~B(){};
static void print(int i);
};
class C
{
public:
C(){};
~C(){};
template< class T >
void test(int num)
{
T::print(num);
};
};
template< class T >
void test(int num)
{
T::print(num);
};
#endif
2、test.cpp
#include <stdio.h>
#include "test.h"
void A::print(int i)
{
printf("A::i = %d\n", i);
}
void B::print(int i)
{
printf("B::i = %d\n", i);
}
void main()
{
C p;
p.test<A>(2); //在VC下有编译错误,用g++再linux下可以正常编译
p.test<B>(2); //在VC下有编译错误,用g++再linux下可以正常编译
}
在VC6.0下编译错误:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
E:\tmp\test.cpp(19) : error C2275: 'A' : illegal use of this type as an expression
e:\tmp\test.h(5) : see declaration of 'A'
E:\tmp\test.cpp(20) : error C2275: 'B' : illegal use of this type as an expression
e:\tmp\test.h(15) : see declaration of 'B'
Error executing cl.exe.
test.exe - 2 error(s), 0 warning(s)
...全文
相关推荐
VC 6.0下编译调试ffmpeg
这样,VC 6.0就能找到SDL的相关头文件和库文件。### 4. 设置VC 6.0项目创建一个新的Win32 Console Application项目,选择"Empty Project"模板。
VC6.0到VS2017编译报错解决办法.docx
### VC6.0到VS2017编译报错解决办法#### 一、概述随着软件开发工具的不断进步,Visual Studio (VS) 的版本也在不断更新,从早期的 Visual C++ 6.0 (简称VC6.0
QT+VC6.0安装编译过程
**测试应用程序**: - 编译完成后,运行应用程序,检查是否有未解决的链接错误或其他问题。通过以上步骤,你就可以在VC6.0环境中利用Qt进行开发了。
VC6.0编译的ucos-II
而UCOS-II的源码设计较为古老,与VC6.0的编译环境更加匹配,这也是很多开发者依然选择在VC6.0下编译UCOS-II的原因。在使用VC6.0编译UCOS-II时,需要注意以下几点:1.
易语言vc6_vc7_vc8_vc9_vc2010到vc2022静态编译12个版本
本篇文章将详细介绍易语言VC静态编译链接器多版本集合,从VC6.0到VC2022,涵盖12个版本的静态编译功能,确保用户能根据需求选择最适合的编译环境。


