[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] C++ Stuff



Mark Duckworth wrote:
T is a buddy class. The vector is defined in the buddylist class. The failure happens when constructing a buddylist.

In such case, write a small testcase.
I did it for you. I made a copy/paste of your snippets in a single source file, plus some glue (see attached file).

For me, it works perfectly. I cross-compiled the source using gcc 4.3.3 and I ran it on Steem (nearly perfect STe emulator - of course without FPU !)

m68k-atari-mint-g++ vect.cpp -o vect.tos

(go to the emulator)

vect
Not crashed ! screenname = bcdef

Try this source on your system to check it is not a compiler issue.
I really think your problem is elsewhere.
Maybe you trashed the stack before calling push_back ?

--
Vincent Rivière
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

class buddy

{

   public:

       string screenname;
       unsigned short int selected;
       unsigned short int highlighted;
       unsigned short int online;
       unsigned short int away;

       struct aim_userinfo_s *userinfo;

       string prof;
       string info;
       int info_display_offset;
       void is_now_online();
       void is_now_offline();
       void is_now_away();
       void is_now_back();
};

class buddylist
{
   public:
       vector<buddy> thelist;
       buddy* find_by_screenname(string in_sn);
       void add(string in_sn);
       buddylist(bool fromdisk);
       void remove(string in_sn);
       void print();
       void save_to_disk();
       string oscar_string();
       class AnError { };
};

buddylist::buddylist(bool fromdisk)
{
	const char* line = "abcdefg";

	buddy mybuddy;
	mybuddy.online=0;
	mybuddy.selected=0;
	mybuddy.away=0;
	mybuddy.highlighted=0;
	mybuddy.screenname=string(line).substr(1, strlen(line)-2);
	mybuddy.userinfo=NULL;
	mybuddy.prof="";
	thelist.push_back(mybuddy);

	cout << "Not crashed ! screenname = " << thelist[0].screenname << endl;
}

int main(int argc, char* argv[])
{
	buddylist bl(true);

	return 0;
}