我只是想了解为什么我不能用这样的大括号创建对象 () 我不明白是什么问题
"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;
}
我收到了这两个错误
<块引用>main.cpp 3 表达式必须有类类型
<块引用>main.cpp 3 left of '.printNodes' 必须有 class/struct/union
答案 0 :(得分:0)
BSNode<int> bsnodeInt1();
声明一个函数。
BSNode<int> bsnodeInt2;
定义了一个新变量,它通过默认构造函数初始化。