Question

How do i make a makefile for 2 template classes in c++ ? for example i...

How do i make a makefile for 2 template classes in c++ ?

for example i have

template <class T>
class item

{

     private:

         T value

     // other code

};

and

template <class T>

class drive

{

       private:

              item<T>* node;

        //more code

};

            

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You should not compile the template files. Template definitions are commonly placed in header files. Therefore, you can save these two template into two separate header files files, named item.h and drive.h.

Include these header files in the main.cpp.

Then write a Makefile:

main.o: main.cpp item.h drive.h
g++ -c -o main.o main.cpp

N.B:  The header files do not require any special extension conveying that they contain templates, although you could give them one, such as .t, if you prefer. The preprocessor will include any file specified in a #include regardless of its name.

Add a comment
Know the answer?
Add Answer to:
How do i make a makefile for 2 template classes in c++ ? for example i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Im making a generic linked list. I cant figure out how to make an object of...

    Im making a generic linked list. I cant figure out how to make an object of my class from main. My 3 files are main.cpp dan.h dan.cpp The error is: 15 6 [Error] prototype for 'void ll<T>::insert()' does not match any in class 'll<T>' #include <iostream> #include <string> #include "dan.h" using namespace std; int main() { ll<int> work; work.insert(55);//THIS IS THE LINE THATS GIVING ME THE ERROR, Without this line it compiles and //runs. } #ifndef DAN_H #define DAN_H #include...

  • Template Deque Class (C++) In this assignment, we will use a given test menu for the template Deq...

    Template Deque Class (C++) In this assignment, we will use a given test menu for the template Deque Class (a Linked List based Double Ended Queue, Deque) that you have put together. Recommended Steps testDeque.cpp : // C++ implementation of doubly linked list Deque doubly linked list #include <bits/stdc++.h> using namespace std; class Timer { // To replace with the full timer class definition // inside this folder: LearnCpp9_18_timeSortArray.cpp }; // Node of a doubly linked list template<class T> class...

  • Template Dequeue Class (C++ ) In this assignment, we will use a given test menu for the template ...

    Template Dequeue Class (C++ ) In this assignment, we will use a given test menu for the template Deque Class (a Linked List based Double Ended Queue, Deque) that you have put together. Starter testDeque.cpp which contains: Timer class holder (you need to go through the LearnCpp Ch15 and import it in) Node class Deque class specification (you need to fill out the definition) here is the testDeque.cpp code: // C++ implementation of doubly linked list Deque doubly linked list...

  • Skills needed to complete this assignment: template metaprogramming. PROGRAMMING LANGUAGE: C++ PROMPT: Write a template version...

    Skills needed to complete this assignment: template metaprogramming. PROGRAMMING LANGUAGE: C++ PROMPT: Write a template version of a class PQueue that implements a priority queue. A priority queue is a list of items that is always ordered by priority. Each item that is added to the list requires an associated priority value, an integer for this problem, where 0 represents the highest priority and larger values are lower in priority. Removing an item from the queue removes the item with...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2: Design (pseudocode) and implement (source code) a class called Counter. It should have one private instance variable representing the value of the counter. It should have two instance methods: increment() which adds on to the counter value and getValue() which returns the current value. After creating the Counter class, create a program that simulates tossing a coin 100 times using two Counter objects (Head...

  • C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS...

    C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)" The objective of the assignment is to revise the public method add in class template LinkedBag so that the new node is inserted at the end of the linked chain instead of at the beginning. This is the code I have: linkedBag-driver.cpp BagInterface.hpp LinkedBag.hpp Node.hpp int main) LinkedBag<string> bag; cout << "Testing array-based Set:" << endl; cout << "The initial bag is...

  • help with C++ code The aim of this is to practice writing template classes. You must...

    help with C++ code The aim of this is to practice writing template classes. You must use SafeArray template class and implement a SafeMatrix template class that will allow you to work with two dimensional arrays of any type. The boundaries are checked. You must be able to create instances of SafeMatrix template class like, SafeMatrix<int> m(2,3); The above statement will create a 2 by 3 dimensional array of integers. You must be able to access and set values using...

  • I'd like to make this portion of my project a recursive function... how can I accomplish...

    I'd like to make this portion of my project a recursive function... how can I accomplish this? This is what I have now. Thank you!! // A wrapper to a recursive method that inverts the contents of the list // @post the contents of the list are inverted such that // the item previously at position 1 is at position item_count_, // the item previously at position 2 is at position item_count_-1 ... // the item previously at position ⌊item_count/2⌋...

  • I have the following c++ data structures assignment: Copy Constructors, Destructors, and Assignment Operators An understanding...

    I have the following c++ data structures assignment: Copy Constructors, Destructors, and Assignment Operators An understanding of how to implement copy constructors, destructors, and assignment operators is essential when working with data structures using dynamic memory allocation. Failure to implement these methods correctly can and probably will result in memory leaks. In this project, you are provided with a working implementation of a doubly-linked list in which the copy constructor, destructor, and assignment operator methods are not complete. To complete...

  • Hi ! I need help please, I want to write java code, but that is difficult...

    Hi ! I need help please, I want to write java code, but that is difficult for me. it is about using annotation, reflection and XLM_ file. Please help me! I want explaintion with code and I want to se result please! My assignment is! Using the annotations and reflection API write an XML file exporter for composite objects of any kind. That is, the exporter should rely only on the annotations in the class definitions of the composite objects...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT