machen ein makefile für eine Vorlage-Klasse

So, ich habe einige Dateien, die ich möchte zu kompilieren zusammen. Einer von Ihnen ist der stack.h mit stack.cpp enthalten.

Das folgende ist meine header-Datei:

#include<iostream>
#ifndef STACK_H
#define STACK_H 
template <class ItemType>
class StackType
{
public:
    //code

private:
    //code   
};
#include "stack.cpp"
#endif

Folgende ist stack.cpp:

#include "stack.h"
#include <iostream>
using namespace std;

template<class ItemType>
StackType<ItemType>::StackType(){
    top = -1;
    MAX_ITEMS = 200;
}

//other codes
}

Wenn ich machen Sie sagt, ich bin die Neudefinition der code in stack.cpp

Folgende ist mein Makefile:

main.o: main.cpp stack.h
    g++ $(CFLAGS) -c -o main.o main.cpp
stack.o: stack.cpp stack.h
    g++ $(CFLAGS) -c -o stack.o stack.cpp

Sehe ich nicht, was das problem ist.

  • Was sagt Sie definieren code? Poste bitte die genaue Fehlermeldung.
InformationsquelleAutor Jack F | 2012-12-09
Schreibe einen Kommentar