error C2275: 'Type' : illegal use of this type of expression

cant figure out the problem and teacher said the vaguest thing
-----------------------------------------------------
node.h
#pragma once
#include <iostream>
#include <iomanip>
#include <cassert>
#include <string>
#include <ctime>
#include <random>
#include<cstdlib>
using namespace std;
template <class Type>
struct nodeType
{
Type info;
nodeType<Type> *link;
};
-------------------------------------------------------------------
factory.h
#pragma once
#include "node.h"

class Factory
{
public:
template <class Type>
nodeType<Type> *createNewNode(Type)
{
return new nodeType<Type>;
}
};
--------------------------------------------------------------------------
linkedlist.cpp

template <class Type>
void linkedListType<Type>::insertLast(const Type& newItem)
{
nodeType<Type> *newNode; //pointer to create the new node

newNode = factory.createNewNode(Type); //create the new node

newNode->info = newItem; //store the new item in the node
newNode->link = NULL; //set the link field of newNode
//to NULL

if (first == NULL) //if the list is empty, newNode is
//both the first and last node
{
first = newNode;
last = newNode;
count++; //increment count
}
else //the list is not empty, insert newNode after last
{
cout << last->info << endl;
last->link = newNode; //insert newNode after last
last = newNode; //make last point to the actual
//last node in the list
count++; //increment count
}
}//end insertLast
-------------------------------------------------
the error keeps bringing me back to
newNode = factory.createNewNode(Type)
any information or the reason why its not working would be great, the rest of my class did not have the problem and the codes look the same so i am thinking it is something stupid i cant figure out
newNode = factory.createNewNode(Type);

What is Type here? Switch on your brain. It is a type. You should specify an argument that is an object when calling a function, not a type.
well fixed it with factory.createNewNode(int());, couldnt understand fully what you was asking vlad, im brand new to c++, data structures, templates
Look at it this way:

1
2
3
4
5
template <class Type>
nodeType<Type> *createNewNode(Type)
{
return new nodeType<Type>;
}


Let's say you want to instantiate this function using, say, int, as the template argument (Actually, I didn't think you could use int, because int is a basic type, not a class, but your code seems to accept it). So, the expansion of the template would be:

1
2
3
4
nodeType<int> *createNewNode(int)
{
return new nodeType<int>;
}


This is a function call that takes an int as an argument and returns a nodeType<int> as a return value. Notice the argument itself is never used.

In the expanded form, the function would be called like this:

1
2
nodeType *newNode;
newNode = createNewNode(5);

You have to pass an int argument (in this example it's 5) to the function.

If you took your statement
newNode = factory.createNewNode(Type); //create the new node

And instantiated it for ints, it would be:
newNode = factory.createNewNode(int); //create the new node

Notice, you are passing a type (int) to a function that requires a value. That's why it doesn't work. When you changed it to
factory.createNewNode(int())
you were actually calling a constructor to create an int object which can be correctly passed to the function.

So, the question I have for you is, do you need to pass an argument to the createNewNode function, or do you want to get rid of the function and call it like
newNode = factory.createNewNode<Type>(); //create the new node






Topic archived. No new replies allowed.