Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this' type variableofType()' function or object?

#include<iostream>
class name
{
public:
    int a;
    name():a(0){};
};
void add(name * pname)
{
    pname = NULL;
}
int main()
{
    name varName();
    name * pName = new name();
    add(pName);
    add(&varName);//error C2664: 'add' : cannot convert parameter 1 from 'name __cdecl *)(void)' to 'name *'
}
like image 437
yesraaj Avatar asked Nov 28 '22 08:11

yesraaj


1 Answers

The error is on the first line of the main function:

name varName();

You are not creating an instance of class name with the default constructor, you are actually declaring a new function called varName, with no parameters, which returns a name instance.

You should instead write:

name varName;
like image 66
MiniQuark Avatar answered Dec 21 '22 07:12

MiniQuark