Missing template arguments before '.' token

Anyone mind to explain why is it? D:

Here is my header file of the linked list (Didn't post the definition. It's very long)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  template<class Type>
class UnorderedLinkedList: public Data
{
public:
    void insertFirst(const Type& newObject);
    void insertLast(const Type& newObject);
    void insertNode(const Type& newObject, int getPosition);
    void displayParticular(const Type& displayObject);
    void displayAll();
    void deleteNode(const Type& deleteObject);
    void deleteAll();
    bool searchList(const Type& searchObject);
    UnorderedLinkedList();
    ~UnorderedLinkedList();


In my main program, I tried to declare the below code but it pops out this thing that I don't know what is wrong with it
1
2
Data AData(1, "string1", "string2", "string3", 50.00, 250.00);
UnorderedLinkedList.insertFirst(AData);

UnorderedLinkedList.insertFirst(AData);

the dot operator (.) needs an object on its left. An object is not a class name, nor is it a template name:

1
2
3
4
5
string foo;  // <- string is the class.  foo is the object

foo.length();  // <- Correct.  Gets the length of the foo object

string.length();  // <-  Error.  Makes no sense.  What string are you getting the length of? 


Also... UnorderedLinkedList isn't even a class -- it's a template, and in order to make it a class you have to tell it what type you want for the 'Type' template argument.

So 2 changes:
1) Give UnorderedLinkedList its necessary template argument
2) Create an object

1
2
3
UnorderedLinkedList<int>  mylist;  // <- <int> tells it that Type=int.  mylist is now the object

mylist.insertFirst(AData);  // <- now this makes sense. 
what if the data is a class? because i wanted to store a collection of information into the list.
I'm sorry, I forgot to mention that Data is a class as follows:
1
2
3
4
5
6
7
8
9
10
11
class Data
{
    friend ostream& operator << (ostream& os, const Data& object);
    bool operator == (const Data& object) const; 
    bool operator >= (const Data& object) const; 
public:
    void setData(int getRegNo, string getType, string getCountry, string getPLocation, double eCapacity, double mPrice);
    void printInfo() const;
    Data();
    Data(int getRegNo, string getType, string getCountry, string getPLocation, double eCapacity, double mPrice);
    ~Data();
what if the data is a class?


That would not change anything I said.



You went through the trouble of making UnorderedLinkedList a template so that you could pick and choose what type you want for the 'Type' argument. This means you can make a list of whatever you want:

1
2
3
4
5
UnorderedLinkedList<int>     aListOfInts;
UnorderedLinkedList<string>  aListOfStrings;
UnorderedLinkedList<Data>    aListOfDatas;

//etc 
Last edited on
thanks a lot , Disch. I was wondering what type is it for the class now it's clear. Appreciate your help so much :D
Topic archived. No new replies allowed.