以下代码有什么问题?
下面的parseCounter1()和parseCounter1()是两个函数.
我把它们的指针放在一起,const OptionValueStruct以便
在option_values []的每个元素
都经过时可以相应地调用它们:
typedef struct OptionValueStruct{
char counter_name[OPTION_LINE_SIZE];
int* counter_func;
} OptionValueStruct_t;
const OptionValueStruct option_values[] = {
{"Counter1", (*parseCounter1)(char*, char**)},
{"Counter2", (*parseCounter2)(char*, char**)},
};
const OptionValueStruct *option = NULL;
for(int i = 0; i< sizeof(option_values)/sizeof(OptionValueStruct_t); i++){
option = option_values + i ;
result = option->counter_func(opt_name, opt_val);
}
Run Code Online (Sandbox Code Playgroud) 我知道如何在构造函数中初始化其他变量,例如 int 或 String,但我不知道如何为 List 和 Map 执行此操作。
class StackOverFlowQuestion{
StackOverFlowQuestion({this.test='', this.map=?, this.list=?});
String test;
Map map;
List list;
}
Run Code Online (Sandbox Code Playgroud)
我应该用什么代替问号?
谢谢。
我的C++有点生疏但我已经制作了一个程序来反转链表,现在我正在尝试为它编写正确的析构函数,但我不知道究竟要销毁什么.这是我的类定义:
class LinkedList
{
private:ListElement *start;
public:LinkedList();
public:void AddElement(int val);
public:void PrintList();
public:void InvertList();
};
class ListElement
{
public:int value;
public:ListElement * link;
public:ListElement(int val);
public:ListElement();
};
class Stack
{
private:ListElement ** stack;
private:int index;
public:Stack(int size);
public:void push(ListElement * le);
public:ListElement * pop();
};
Run Code Online (Sandbox Code Playgroud)
堆栈用于反转列表时.无论如何......我将如何为这些编写析构函数?我刚在想:
对于ListElement,使值为0,链接为0(NULL).
对于LinkedList,遍历元素并为所有元素调用ListElementDestructor.
我不是很确定这一点,因为我理解析构函数会自动调用成员对象的析构函数,所以在这种情况下只能为LinkedList写一个空的析构函数吗?我不知道......这就是我要问的原因
对于堆栈,我不知道......在反转列表之后,指针已经为0(NULL),因为它们都是poped.
我有点困惑.有人可以帮忙吗?先感谢您.
我已经以这种方式在 Dart 中创建了我的类,但是我Non-nullable instance field 'text' must be initialized. Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'.想知道是否有一种方法可以以“Python”风格来创建这种类,在此先感谢您。
class Lexer {
String _text;
int _pos;
String _current_char;
Lexer(String text) {
this._text = text;
this._pos = -1;
this._current_char = '';
this.advance();
}
void advance() {
this._pos++;
this._current_char = this._pos < this._text.length ? this._text[this._pos] : '';
}
}
Run Code Online (Sandbox Code Playgroud) 我正在查看关于单选按钮的 flutter 官方文档,并注意到枚举已在类之外声明。为什么我们不能在类内部声明它们,如果可以,在类内部和外部声明它们有什么区别?
这是示例代码:
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const Center(
child: MyStatefulWidget(),
),
),
);
}
}
enum SingingCharacter { lafayette, jefferson }
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
SingingCharacter? _character = SingingCharacter.lafayette; …Run Code Online (Sandbox Code Playgroud) 我有一个通用StatefulWidget类,它有一个Function回调的通用类。当我尝试调用该回调时,我得到一个运行时TypeError:
\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following _TypeError was thrown building MyStatefulWidget<int>(dirty, state:\nMyState<int>#cacb3):\ntype \'(int) => Widget\' is not a subtype of type \'(dynamic) => Widget\'\n\nThe relevant error-causing widget was:\n MyStatefulWidget<int>\n MyStatefulWidget:file:///path/to/my_flutter_project/lib/main.dart:11:13\n\nWhen the exception was thrown, this was the stack:\n#0 MyState.build (package:my_flutter_project/main.dart:33:19)\nRun Code Online (Sandbox Code Playgroud)\n可重现的例子:
\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following _TypeError was thrown building MyStatefulWidget<int>(dirty, state:\nMyState<int>#cacb3):\ntype \'(int) => Widget\' is not a subtype of type \'(dynamic) => Widget\'\n\nThe relevant …Run Code Online (Sandbox Code Playgroud)