Stack クラスで問題が発生しています。私にはすべて問題ないように見えますが、何かが欠けている可能性があります。私はメイクファイルがそれほど得意ではないので、メイクファイルに何かあるのではないかと思いました。
また、いくつかの異なる質問に目を通しましたが、問題を解決するものは見つかりませんでした。
これは、私がコンパイルしているすべてのコードとメイクファイルです。
Stack.h:
#ifndef STACK_H
#define STACK_H
#include "Node.h"
template<class Type>
class Stack
{
public:
Stack();
void push(Type );
Type pop();
bool isEmpty() const;
protected:
Node<Type> *head;
};
#endif
スタック.cpp:
#include "Stack.h"
template<class Type>
Stack<Type>::Stack()
{
head = NULL;
}
template<class Type>
void Stack<Type>::push(Type element)
{
Node<Type> *newNode;
newNode = new Node<Type>;
newNode->data = element;
newNode->next = head;
head = newNode;
}
template<class Type>
Type Stack<Type>::pop()
{
Node<Type> *current = head;
Type element = current->data;
head = head->next;
delete current;
return element;
}
template<class Type>
bool Stack<Type>::isEmpty() const
{
return head == NULL;
}
Node.h:
#ifndef NODE_H
#define NODE_H
#include "Matrix.h"
template<class Type>
struct Node
{
Type data;
Node<Type> *next;
};
#endif
main.cpp:
#include "Stack.h"
#include <iostream>
using namespace std;
int main()
{
Matrix m1;
Matrix m2(1, 2, 3, 4);
Matrix m3;
m3 = m1 + m2;
Stack<Matrix> stack;
cout << stack.isEmpty() << endl;
return 0;
}
メイクファイル:
all: matrix
matrix: removal main.o Matrix.o Stack.o
g++ -o matrix main.o Matrix.o Stack.o
main.o: main.cpp
g++ -c -g main.cpp
Matrix.o: Matrix.cpp
g++ -c -g Matrix.cpp
Stack.o: Stack.cpp
g++ -c -g Stack.cpp
removal:
rm -f *.o
Matrix.h/Matrix.cpp が必要な場合は、お知らせください。それらは行列で数学を行うためのものであり、私が知る限り問題を引き起こしていません (問題なくコンパイルされています)。