在cpp头文件中使用外部变量

Using extern variables in a Cpp-header

本文关键字:外部 变量 cpp 文件      更新时间:2023-10-16

我在cpp的头文件中使用外部变量有一些问题。

所以我有我的(简化)cppfiles如下:

<标题> Header.h h1> MainFile.cpp h1> Casual.cpp h1> 在当我编译这个的时候,它会编译。但是在运行程序时,它会中止告诉我

CXX0030:错误:表达式不能求值

有谁知道是什么问题吗?

在CalculateHeight定义的Casual.cpp中出现错误。这行写着:

coordinates.push_front(Point(x,y,root->data));

添加

定义后
BstNode* GetNewNode( int d ){
  BstNode* res = new BstNode();
  res->data = d;
  return res;
}

程序执行:

Creating test-structure...
Width: 6
checkcheck(3,-1)
(2,-1)
(1,-1)
(3,1)
(2,1)
(1,1)
(5,0)
(4,0)
(3,0)
(2,0)
(1,0)
(0,0)
Height: 3

我没有验证这个;-)