3 Replies - 1218 Views - Last Post: 17 March 2009 - 09:02 PM Rate Topic: -----

#1 kaantexas  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 12-January 08

Template Function/Template Class

Post icon  Posted 12 March 2009 - 12:24 AM

sequenceTest.cpp:23: error: variable or field `show_list' declared void
sequenceTest.cpp:23: error: template declaration of `int show_list'
sequenceTest.cpp:23: error: missing template arguments before "src"
sequenceTest.cpp:23: confused by earlier errors, bailing out
make: *** [sequenceTest.o] Error 1


I finished all the coding but however I have a compiler error. I use Linux.
I have "sequence.h", "sequence.template" and "sequenceTest.cpp" files. The error points to "sequenceTest.cpp" files which is on the top. I am trying to understand what I am missing.


sequnce.h file:
---------------------------------------
#ifndef SEQUENCE_H
#define SEQUENCE_H

#include <cstdlib>  // provides size_t

namespace sequenceOfNum
{
   template <class Item>
   class sequence
   {
   public:
	  // TYPEDEFS and MEMBER CONSTANTS
	  typedef Item value_type;
	  typedef size_t size_type;
	  static const size_type CAPACITY = 10;
	  // CONSTRUCTOR
	  sequence();
	  // MODIFICATION MEMBER FUNCTIONS
	  void start();
	  void advance();
	  void insert(const Item& entry);
	  void attach(const Item& entry);
	  void remove_current();
	  // CONSTANT MEMBER FUNCTIONS
	  size_type size() const;
	  bool is_item() const;
	  value_type current() const;

   private:
	  Item data[CAPACITY];
	  size_type used;
	  size_type current_index;
   };
}

namespace sequenceOfChar
{
   template <class Item>
   class sequence
   {
   public:
	  // TYPEDEFS and MEMBER CONSTANTS
	  typedef Item value_type;
	  typedef size_t size_type;
	  static const size_type CAPACITY = 10;
	  // CONSTRUCTOR
	  sequence();
	  // MODIFICATION MEMBER FUNCTIONS
	  void start();
	  void advance();
	  void insert(const Item& entry);
	  void attach(const Item& entry);
	  void remove_current();
	  // CONSTANT MEMBER FUNCTIONS
	  size_type size() const;
	  bool is_item() const;
	  Item current() const;

   private:
	  Item data[CAPACITY];
	  size_type used;
	  size_type current_index;
   };
}

#include "sequence.template"
#endif



sequence.template file:
---------------------------------------------------
#include <cassert>
//#include "sequence.h"

namespace sequenceOfNum
{
   template <class Item>
   const typename sequence<Item>::size_type sequence<Item>::CAPACITY;    

   template <class Item>
   sequence<Item>::sequence() : used(0), current_index(0) { }

   template <class Item>
   void sequence<Item>::start() { current_index = 0; }
................................
.............................
namespace sequenceOfChar
{
   template <class Item>
   const typename sequence<Item>::size_type sequence<Item>::CAPACITY;


.................................
............................



And sequenceTest.cpp file:
------------------------------------
#include <cctype>      // provides toupper
#include <iostream>    // provides cout and cin
#include <cstdlib>     // provides EXIT_SUCCESS
#include "sequence.h"
namespace seqOfNum = sequenceOfNum;
namespace seqOfChar = sequenceOfChar;
using namespace std;

// PROTOTYPES for functions
void print_menu();
char get_user_command();
void show_list(seqOfNum::sequence src);
void show_list(seqOfChar::sequence src);
int get_object_num();
double get_number();
char get_character();

int main(int argc, char *argv[])
{
   seqOfNum::sequence s1;  // A sequence of double for testing
   seqOfChar::sequence s2; // A sequence of char for testing
   int objectNum;    // A number to indicate selection of s1 or s2
   double numHold;   // Holder for a real number
   char charHold;    // Holder for a character
   char choice;     
...............
...................
void show_list(seqOfNum::sequence src)
{
   for ( src.start(); src.is_item(); src.advance() )
      cout << src.current() << "  ";
}

void show_list(seqOfChar::sequence src)
{
   for ( src.start(); src.is_item(); src.advance() )
      cout << src.current() << "  ";
}



Thanks for help!

** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Template Function/Template Class

#2 DemonGal711  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 25-September 08

Re: Template Function/Template Class

Posted 12 March 2009 - 01:48 AM

My guess would be that you missed something like a semi colon or a closing bracket so it just shifted everything down.

I would assume it's taking the int from in front of the main call, applying it to the show_list function, moving void to the src variable, and then the compiler just stopped. Go check for small things like that, closing brackets, parentheses, and other small coding errors that can sneak in without you noticing.
Was This Post Helpful? 0
  • +
  • -

#3 kaantexas  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 12-January 08

Re: Template Function/Template Class

Posted 12 March 2009 - 02:22 PM

View PostDemonGal711, on 12 Mar, 2009 - 12:48 AM, said:

My guess would be that you missed something like a semi colon or a closing bracket so it just shifted everything down.

I would assume it's taking the int from in front of the main call, applying it to the show_list function, moving void to the src variable, and then the compiler just stopped. Go check for small things like that, closing brackets, parentheses, and other small coding errors that can sneak in without you noticing.


**********************************

Thanks for your help. I looked at all semicolons and brackets,...I think all are ok.
I thought I didn't use template function right on the show_list function correctly. But I am not sure exactly where I messed up.

This post has been edited by kaantexas: 12 March 2009 - 02:23 PM

Was This Post Helpful? 0
  • +
  • -

#4 kaantexas  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 12-January 08

Re: Template Function/Template Class

Posted 17 March 2009 - 09:02 PM

View Postkaantexas, on 12 Mar, 2009 - 01:22 PM, said:

View PostDemonGal711, on 12 Mar, 2009 - 12:48 AM, said:

My guess would be that you missed something like a semi colon or a closing bracket so it just shifted everything down.

I would assume it's taking the int from in front of the main call, applying it to the show_list function, moving void to the src variable, and then the compiler just stopped. Go check for small things like that, closing brackets, parentheses, and other small coding errors that can sneak in without you noticing.


**********************************

Thanks for your help. I looked at all semicolons and brackets,...I think all are ok.
I thought I didn't use template function right on the show_list function correctly. But I am not sure exactly where I messed up.


Any update(s)?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1