【发布时间】:2020-12-31 13:36:16
【问题描述】:
我只是想了解为什么我不能用这样的大括号创建对象 () 我不明白是什么问题
“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 表达式必须有类类型
'.printNodes' 左边的 main.cpp 3 必须有类/结构/联合
【问题讨论】:
-
因为第一个版本是函数声明,不是变量声明。
标签: c++