1

I have the following header file:

#ifndef DATABASE_H
#define DATABASE_H


#include <vector>
#include <iostream>
#include <string>

#include "record.h"

using namespace std;

template <class value>
class Database {

  public:

    void write (ostream& out, DBScope scope) const;

    Database <value>() {};
    ~Database();

  private:

    vector <Record<value> > records;

};

#include "database.tem"

#endif

database.tem:

template <class value>
void Database<value>::write (ostream& out, DBScope scope) const {

 class vector <Record <value> >::iterator itr = records.begin();

 switch (scope) {

    case AllRecords:
      for (; itr != records.end(); itr++) out << itr;
      break;
    case SelectedRecords:
      for (; itr != records.end(); itr++) {
        if (itr.isSelected) out << itr;
      }
      break;

  }
}

I was running this header a long with another file and produced this error message, noting that in my header file I have another file called database.tem which is #include "database.tem" into my database.h file:

    database.tem: In member function 'void Database<value>::write (std:: ostream&, DBScope) const [with value = int]':
database.tem: In member function 'void Database<value>::write(std::ostream&, DBScope) const [with value = int]':
interactive.cpp:285:   instantiated from 'bool WriteCommand(Database<value>&) [with value = int]'
interactive.cpp:127:   instantiated from 'bool DispatchCommand(CommandT, Database<value>&) [with value = int]'
interactive.cpp:74:   instantiated from 'void MainLoop(Database<value>&) [with value = int]'
interactive.cpp:99:   instantiated from here
database.tem:6: error: conversion from '__gnu_cxx::__normal_iterator<const Record<int>*, std::vector<Record<int>, std::allocator<Record<int> > > >' to non-scalar type '__gnu_cxx::__normal_iterator<Record<int>*, std::vector<Record<int>, std::allocator<Record<int> > > >' requested
interactive.cpp:285:   instantiated from 'bool WriteCommand(Database<value>&) [with value = int]'
interactive.cpp:127:   instantiated from 'bool DispatchCommand(CommandT, Database<value>&) [with value = int]'
interactive.cpp:74:   instantiated from 'void MainLoop(Database<value>&) [with value = int]'
interactive.cpp:99:   instantiated from here
database.tem:11: error: no match for 'operator<<' in 'out << itr'

I have no idea what this messsage is talking about, can someone help me

8
  • 3
    It would help if you'd put the full error message, and the piece of code on which you get it...
    – littleadv
    Commented Sep 30, 2011 at 10:03
  • Please, post database.tem file and #include sentences in database.h. Let's see whats happening.
    – Tio Pepe
    Commented Sep 30, 2011 at 10:05
  • @littleadv the error is around 100 lines long, and the code is even more, I'll add some of the code and see if it helps I don't want to copy/paste the whole thing
    – SNpn
    Commented Sep 30, 2011 at 10:05
  • @SNpn: please put at least the lines following the error lines you posted
    – jopasserat
    Commented Sep 30, 2011 at 10:07
  • @SNpn - most of these lines are the templates. Somewhere inside that text the actual error message is buried. Find it, and bring it here. You don't expect us to just guess it, do you ?
    – littleadv
    Commented Sep 30, 2011 at 10:07

3 Answers 3

2

The first error has to do that the method is const, hence records is const, and reconds.begin() returns a const_iterator.

template <class value>
void Database<value>::write (ostream& out, DBScope scope) const {

 vector <Record <value> >::const_iterator itr = records.begin();

The second error means that you probably meant to dereference the iterator:

for (; itr != records.end(); itr++) out << *itr;
1

It looks like you have only posted a partial error message but the error is probably that you need to write itr->isSelected rather than itr.isSelected.

Also it's preferable to use ++itr instead of itr++ when using iterators.

0

What you are trying to print is iterator object, not the value it refer to:

out << itr;

Replace that with

out << *itr;

Also make sure that class Record has either method or function defined:

ostream& out operator <<(ostream& out); // method

ostream& out operator <<(ostream& out, const Record &); //function
1
  • i've tried that and it still gives me that error: conversion from '___gnu etc error
    – SNpn
    Commented Sep 30, 2011 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.