473,383 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Static object initialization issue..

1
Hi Everybody,
I have the following class structure. When compiled with arm compiler the code works fine but when I try to run the same in GCC4.1.2 i am getting segment fault. On analysis I found that the constructor of B is called first.. ie. even before calling the constructor for the static object named 'trouble1' in the below code.

---------A.hpp-------------------------
class A;
class A
{
public :
int val;
std::string name;
A(int i, string str);
A(A a);
static const A trouble1;
int val();
std::string getName();
-----
----
}

---------A.cpp----------------------------

const A A::trouble1(1,"str1")

int val(){return val;}
std::string A::getName{return name;}

A(int i, string str ) : val(i), name(str){}

A(A a): val(a.val()), name(a.getName()){}

-----------B.hpp-------------

#include "A.hpp"

class B : public A
{
public :
B() ;
---
----
}

-------------B.cpp-----------

B::B():A(trouble1){}


Both this files are in a single libraray module. While loading the library my application crashes.

I feel this is the compiler dependent behaviour. Is there any way to make it running with GCC4.1.2 and g++4.1.2.

Any help or suggestion is appreciated..

thanks
vjn
Feb 15 '08 #1
1 1462
weaknessforcats
9,208 Expert Mod 8TB
Read this: http://www.thescripts.com/forum/thread737451.html.

And post again if you are still having problems.
Feb 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Qin Chen | last post by:
I will present very long code, hope someone will read it all, and teach me something like tom_usenet. This question comes to me when i read <<Think in C++>> 2nd, chapter 10 , name control,...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
1
by: bvisscher | last post by:
I posted this recently in microsoft.public.vc.language and was redirected here. I also searched this ng and found some relavant threads. The most relavent I found was: ...
4
by: mnowosad | last post by:
As far I know, static variables are tied to AppDomain scopes. So, every time an executing code within an AppDomain references a class for the the first time since the AppDomain was created/loaded,...
9
by: Allen | last post by:
In a static library, there is a static variable definition. static CLogger::mapFile; In both EXE and DLL, I use the same code. CLogReader uses CLogger::mapFile to do some work. CLogReader...
6
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
1
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the...
20
by: JohnQ | last post by:
The way I understand the startup of a C++ program is: A.) The stuff that happens before the entry point. B.) The stuff that happens between the entry point and the calling of main(). C.)...
6
by: gs | last post by:
Hi, I want to know that when memory get allocated to static data member of a class. class A { static int i; }
17
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.