为什么我使用此代码会出现分段错误?
/* solver.h header file */
10 struct options{
11 unsigned int one:1, two:1, three:1, four:1, five:1, six:1, seven:1, eight:1, nine:1;
12 };
13
14
15 /* structure to describe a cell */
16 struct cell{
17 short value;
18 struct options open_options;
19 };
Run Code Online (Sandbox Code Playgroud)
solver.c:
5 #include <stdio.h>
6 #include "solver.h"
7
8
9
10
11
12 int main(){
13 struct cell board [9][9];
14 int i=0,j=0;
15
16
17 for(i = 1; i<10; i++)
18 for(j = 1; …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个balance_bst(bstNode root)函数,但我正在努力实现.
我正在将该函数实现为模板函数,因为我的bstNode类是一个模板类.
这是(部分)我的代码:
template<class Item, class Key>
class bstNode{
public:
//Constructor
bstNode(const Item& init_data = Item(), const Key& init_key = Key(), bstNode<Item, Key>* l_child = NULL, bstNode<Item, Key>* r_child = NULL){
data_field = init_data;
key_field = init_key;
l_ptr = l_child;
r_ptr = r_child;
}
//Destructor
~bstNode(){
data_field = 0;
key_field = 0;
l_ptr = r_ptr = NULL;
}
//Basic Member Functions
bstNode<Item, Key>*& left( ) { return l_ptr; } //returns left child pointer by reference
bstNode<Item, Key>*& right( ) …Run Code Online (Sandbox Code Playgroud) 我对C++编程很新,我一直在收到一个我似乎无法弄清楚的错误.我尝试了很多不同的方法,只是得到相同错误的变化.这是错误和我的代码:
account.cxx: In member function ‘char* account::get_name() const’:
account.cxx:26: error: invalid conversion from ‘const char*’ to ‘char*’
//File: account.h
68 class account
69 {
70 public:
71 typedef char* string;
72 static const size_t MAX_NAME_SIZE = 15;
73 // CONSTRUCTOR
74 account (char* i_name, size_t i_acnum, size_t i_hsize);
75 account (const account& ac);
76 // DESTRUCTOR
77 ~account ( );
78 // MODIFICATION MEMBER FUNCTIONS
79 void set_name(char* new_name);
80 void set_account_number(size_t new_acnum);
81 void set_balance(double new_balance);
82 void add_history(char* …Run Code Online (Sandbox Code Playgroud)