【发布时间】:2015-05-30 16:04:42
【问题描述】:
我已经看到了很多关于这个问题的答案,知道要寻找什么并且仍然可以看到。看起来有些明显的问题。
算法.h:
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include <iostream>
using namespace std;
template <typename T>
class Algorithm
{
private:
T data;
T result;
public:
Algorithm(T in){
data = in;
}
void compute();
void displayData(){
cout<<data<<endl;
}
T getResult(){
return result;
}
};
#endif // ALGORITHM_H
泡泡.h:
#ifndef BUBBLE_H
#define BUBBLE_H
#include "algorithm.h"
class Bubble : public Algorithm{
public:
Bubble();
};
#endif // BUBBLE_H
main.cpp
#include "bubble.h"
#include <iostream>
using namespace std;
int main()
{
Algorithm<int> a(1);
Algorithm<char> b('a');
a.displayData();
b.displayData();
return 0;
}
错误是:
/home/user/Projects/Algorithms/main.cpp:1:在包含的文件中 ../Algorithms/main.cpp:1:0: /home/user/Projects/Algorithms/bubble.h:6: 错误:“{”令牌类气泡之前的预期类名:公共 算法{ ^
为什么编译器看不到算法类?我将它包含在 Bubble.h 中,所以呢?
【问题讨论】:
标签: c++ inheritance