g++ segfaults

Ok, I'm experiencing something really weird here.

I'm trying my hands on this ai-tutorial: http://www.ai-programming.com/bot_tutorial.htm/#intro

I've defined a class called Bot that constitutes the actual AI, and a class called FBot which handles Qt interface stuff. This is the Bot.h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#ifndef __BOT__
#define __BOT__

#include <QtGui>

typedef struct {
	QString input;
	QString output;
} knowledge_bit;

class Bot {
	public:
		Bot(QString n);
		~Bot(void);

		QString getReply(QString input);

	private:
		QString name;
		knowledge_bit knowledge[2];
};

#endif 


The knowledge array is being initialized in the Bot constructor like this:
knowledge = {{"Hello", "Hi!"}, {"How are you?", "I'm good, thanks!"}}; (I know, very crude and silly:p)

I've tried various ways of initializing the knowledge array, like outside the class, and in the definition, but none of them have worked. I've also tried making it a pointer instead of an array, to no avail. I'm trying to compile this like it is now, with the length of the array set to 2, and g++ itself segfaults! This the message I got:


Bot.cpp: In constructor ‘Bot::Bot(QString)’:
Bot.cpp:11: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.4/README.Bugs> for instructions.


Obviously it is concerning the initialization of the array, but now I've tried everything I can think of. Does anyone know how I can initialize this array? And how did this cause g++ to segfault?

Peace,
Fafner
you are using QString not std:string as in the example

obviously it will not initialise in this manner.
your initialiser is all wrong, too many curly brackets anyway.

try like in the example?


1
2
3
4
5
6
7
        std::string Response[] = {
                "I HEARD YOU!",
                "SO, YOU ARE TALKING TO ME.",
                "CONTINUE, I¿M LISTENING.",
                "VERY INTERESTING CONVERSATION.",
                "TELL ME MORE..."
        };




Last edited on
Ok, I thought QString would initialize the same way. Anyhow, changing it to std::string still produced the same error, so I'm guessing that is actually the case. I'm not using the first, but the second part in the example, so the std::string array isn't part of it anymore. My initializer is exactly the same as in the code in the example, and I can't see how it has too many curly brackets?
Initialisation of class array members is always an issue.
They cannot be initialised in the initialisation list or in the body of the constructor using the usual
array_name = { } style.

If you want other than the default initialisation you wil have to write a loop or something - but NOT the way you
are trying to do.
Topic archived. No new replies allowed.