delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/01/11:30:03

From: "Christo Fogelberg" <doubtme AT hotmail DOT com DOT nospam>
Newsgroups: comp.os.msdos.djgpp
Subject: Question
Date: Wed, 1 Sep 1999 19:21:39 +1200
Organization: The Internet Group (Dunedin)
Message-ID: <936170772.581298@Chaos.es.co.nz>
NNTP-Posting-Host: news.dun.ihug.co.nz
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Cache-Post-Path: Chaos.es.co.nz!unknown AT p81-max8 DOT dun DOT ihug DOT co DOT nz
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Lines: 218
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

<full code at bottom, reduced code in main body, apologies for the length of
this post>

OK, first of all I don't actually know if this is a problem with DJGPP or
not, but I was told (in comp.lang.learn.c-c++) that the code compiled fine
on VC++6 SP3.
Then again, a search of the faq, buglist, mailing list etc didn't reveal any
indication that such a bug existed either.

So - my question is, is my problem a known bug in DJGPP? A configuration
error? Or is it actually in the code and MS's bizarre compiler somehow
turned it into working code?

The problem involves a DataBase<T>, which holds vector<T> (in this case
using a test class - TestData, with the T being specified in another file
with certain functions it must have. I get the following error messages:

In method void DataBase<T>::Search():
    Error: parse error before '.'

and, again in Search:
    Error: cannot call member function 'TestData::Check(TestData &)' without
object

The specfic, reduced, code for each error is:
void DataBase<T>::Search()
{
        // Parse error occurs in the following line at the period, adding
angle
        // brackets to the T indicates it occurs before the '<' however.
        // This error occurs when the class is instantiated.
        T.SearchFor();

        bool searchGood = false;
        char buffer[80];

        for(int i = 1; i = itsNumEntries; i++)
        {
           // This line causes the error, it is being passed an element of
the vector holding T
           // as a reference.
           // This error occurs when the function is called.
           searchGood = T::Check(itsDataList[i]);
        }
}

Thanks in advance for any help! :)

(full code for reduced program that compiles and produces error follows)

Christo Fogelberg





Full Code of the Reduced Program (should compile apart from these two
errors)

// Database Engine.
//
#include <fstream>
/*using whole namespace temporarily, to ensure not cause.
using std::cin;
using std::cout;
using std::endl;
*/
using namespace std;

#include "tbase.hpp"

// The Class Held in the Database:
#include "tdata.hpp"


int main()
{
        DataBase<TestData> TheDBase;
        TheDBase.Search();
        return 0;
}




tbase.hpp:


// Needed STL Classes:
#include <vector>
/*using std::cout;
using std::cin;*/
// Other Vector functions:using std::
using namespace std;

template <class T>
class DataBase
{
public:
        // Constructors, Destructors
        DataBase();
        DataBase(const DataBase& rhs);
        ~DataBase();

        void Search();

private:
        // Contained Datalist:
        vector<T> itsDataList;
        int itsNumEntries;
};

// Searches database using several child functions belonging to T
template <class T>
void DataBase<T>::Search()
{
        T.SearchFor();

        bool searchGood = false;
        char buffer[80];

        for(int i = 1; i = itsNumEntries; i++)
        {
           searchGood = T::Check(itsDataList[i]);
        }
}



tdata.hpp


/*
using std::cout;
using std::cin;
using std::endl;*/
using namespace std;

class TestData
{
        public:
                // Constructors
                TestData();
                ~TestData();
                TestData(const TestData& rhs);

                // Overloaded Operators
                inline friend istream& operator>>(istream& stream, TestData&
data);
                inline friend ostream& operator<<(ostream& stream, const
TestData& data);

                int GetItsAge() const { return itsAge; }

                // Other Required Functions
                void SearchFor();
                bool Check(TestData& toCheck);

        private:
                // Class Data
                int itsAge;

                // Search Data
                static int sItsAge;
};

// Declare Search Data (Statics)
int TestData::sItsAge = 0;

TestData::TestData()
{
/*
Stubbed
*/
}

TestData::~TestData()
{
        // Stubbed, might be needed.
}

TestData::TestData(const TestData& rhs)
{
       itsAge = rhs.GetItsAge();
}

istream& operator>> (istream& theStream, TestData& theData)
{
/*
Stubbed
*/
}

ostream& operator<< (ostream& theStream, const TestData& theData)
{
/*
Stubbed
*/
}

void TestData::SearchFor()
{
/*
Stubbed
*/
}

bool TestData::Check(TestData& toCheck)
{
/*
Stubbed
*/
}





- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019