0

i just want to understand why i cant create object with braces like this () i dont understand what is the problem

"BSNode.h"

#pragma once

#include <string>
#include <iostream>

template <class T>
class BSNode
{
public:
    BSNode() {
        
    }
    void printNodes() const {
        std::cout << "test" << std::endl;
    }
};

"main.cpp"

#include "BSNode.h"

int main()
{
    BSNode<int> bsnodeInt1();
    BSNode<int> bsnodeInt2;
    bsnodeInt1.printNodes();
    bsnodeInt2.printNodes();
    return 0;
}

im getting this two errors

main.cpp 3 expression must have class type

main.cpp 3 left of '.printNodes' must have class/struct/union

MrDakik
  • 114
  • 6
  • 1
    Because the first version is a function declaration, not a variable declaration. – john Dec 31 '20 at 13:45
  • This may help: [https://softwareengineering.stackexchange.com/questions/133688/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax](https://softwareengineering.stackexchange.com/questions/133688/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax) – drescherjm Dec 31 '20 at 13:54

1 Answers1

1

BSNode<int> bsnodeInt1(); declares a function.

BSNode<int> bsnodeInt2; defines a new variable, it is initialized through the default constructor.

Quimby
  • 17,735
  • 4
  • 35
  • 55
User
  • 572
  • 2
  • 10