debugging problem
&nbsp(474 Views)
I'm developing software for Linux on my desktop. The software gets compiled
and the binary is downloaded to the target system where i can't install a
debugging system or something.
I've written following code:
#ifdef INIT_REPORT
std:fstream out("/usr/share/NovaxTSP/INITreport.txt", std::ios_base::in |
std::ios_base:ut | std::ios_base::app);
if(!out) { // if out couldn't be opened, print error and exit
std::cout

pointerproblem with derived class
&nbsp(236 Views)
,
I have a number of classes, base classes an derived which use pointers to
objects of each other. Now there are problems with the types.
I best explain with an example. I name one line of classes A and one B:
class Tbase_A
{
// some properties and methods
}
class Tbase_B
{
Tbase_A ** List_ptr_base_A
// more properties
// methods do some work on a list of pointers of Tbase_A like storing
data of all those base_A objects to a file
void __fastcall do_something (void);
}
class Tderived_A : public Tbase_A
{
more properties and methods
}
My current project only works with Tderived_A.
I have a list of pointers to a number of objects of type Tderived_A on which
I wish to use the methods of Tbase_B:
Now I tried two possibilities:
Tderived_A ** List_ptr_derived_A [] =
{
&obj1_derived_A,
&obj2_derived_A,
&obj3_derived_A,
&obj4_derived_A,
//....
}
And then in the program:
obj_base_B.List_ptr_base_A = List_ptr_derived_A;
This fails at compilation, because the types are not equal.
If I change the type of the list:
Tbase_A ** List_ptr_derived_A [] =
{
&obj1_derived_A,
&obj2_derived_A,
&obj3_derived_A,
&obj4_derived_A,
//....
}
And then in the program:
obj_base_B.List_ptr_base_A = List_ptr_derived_A;
This is ok at compile time. But this:
obj_base_B.do_something ();
fails at runtime, execution ends in a mess of misinterpreting data of the
objects. As much as I have seen this comes from interpreting the data
structure of an object of type Tderived_A as if it was Tbase_A. So it seems
there is an implicit type cast done, when I set addresses of objects of
T_derived_A in a list of type addresses of Tbase_A.
I understand that both cannot work.
But where is a way to get the functions that are there in Tbase_B to work on
objects of Tbase_A also to work on objects of Tderived_A.
I hope I could clearly describe my problem.
Thank you for any help.
Martin

problems with inheritance and protected attributes
&nbsp(447 Views)
all,
I'm working on a project with a layout similar to this:
class A {
protected:
A *next;
int i;
public:
void m(A *a);
};
class B: public A {
public:
void m(B *b);
}
where both A and B are linked lists, but each one of its own type, and
m is a method that manipulates A's 'next' attribute, for instance:
A::m(A *a) {
a->next = next;
i++;
}
as the behavior would be exactly the same for B, I did:
B::m(B *b) {
A::m(b);
}
But that gives me errors on compiling whenever method B::m, tries to
access a protected member of class A (for instance incrementing i).
I've tried declaring a new variable i to class B, but that just causes
both A::i and B::i to exist, and A increments A::i, while whenever
someone reads from B, it reads B::i. Which is obviously wrong.
Does anybody know how I can fix this Did anybody even understand what
I just asked I know I kinda lost me. :P
Any help would be greatly appreciated,
Lucas , * Lucas Kanebley Tavares:
> On Sep 30, 3:23 am, "Alf P. Steinbach" wrote:
>> It would be nice if you posted the actual offending code, but happily
>> this "problem" is not uncommon, so it is reasonable to assume you have
>> something like
>>
>> B::m( B* b )
>> {
>> A::m( b );
>> next->i = 666;
>> }
>>
>> That will cause the compiler to complain, because while B can access
>> protected A features on B objects, and on objects of classes publicly
>> derived from B, if it could do it could access protected A features on A
>> objects it could also access protected A features on Z-objects, where Z
>> is a class I have derived from A.
>>
>> So in that case "protected" wouldn't be any protection: you could access
>> protected A features of my Z instances simply by deriving a class from A.
>>
>> So C++ does not allow that.
>
> --- Compiler error
> wwperiod.hpp: In member function 'virtual double
> ZWPeriod::getMinimalCost()':
> wwperiod.hpp:50: error: 'DATATABLE* WWPeriod::resTable' is protected
> zwperiod.cpp:46: error: within this context
> (and the same error for a lot of other attributes in the same
> method).
>
> --- Classes layout
> class WWPeriod {
> public:
> virtual double getMinimalCost();
> protected:
> DATATABLE *resTable;
>
> };
>
> class ZWPeriod: public WWPeriod {
> public:
> virtual double getMinimalCost();
>
> };
>
> --- Line giving the presented error:
> zwperiod.cpp:46: resTable[0].tempCost = prev->resTable[0].tempCost +
> prev->holdCost;
>
> ---
>
> I'm a reasonably good C programmer, but although I know C++ syntax,
> I've never really had any serious projects in C++, so I'm
> unexperienced.
>
> Thank you for your reply, but my problem remains.
> Any more suggestions for a n00b
Only to reconsider the above earlier suggestion, which is now confirmed.
The (or at least one) problem is the attempted access via prev->, as I
surmised it would be. Why that is not permitted is explained above.
How to possibly fix it, explained above -- and perhaps also take a
look at the suggested redesign. In addition to the earlier advice, with
concrete code I can now make the suggestion to introduce public inline
const accessors tempCost() and holdCost() in the base class, and change
the naming convention for data members to e.g. myTempCost or tempCost_.
By the way, please don't top-post (rearranged, see the FAQ please), and
please don't quote signatures.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail

please help - file input problems
&nbsp(326 Views)
I'm reading in a datafile that is primarily stored as 1-byte ints.
I've tried using cin, fread, fgetc, and fscanf - but all these methods
ignore a value of 13 and skip it entirely, returning the next value
instead.
What method can i use that will not strip data out as whitespace

Navigation and understanding problems with C++ code, Please help
&nbsp(376 Views)
Experts & Beginners,
I'm definitely not an expert, but believe that can become one day....and
the journey has already started....and here is a possible milestone, if
you can help.
I work for a company that has a very nice embedded product, and I have
been involved in system design and testing for this product. Now, I am
trying to get some understanding of software, which is a model-based C+
+ software. It is developed using Rhapsody. My question is: I am not
able to follow the huge code with several packages and libraries with
accurate understanding since I have not written it. I am confused by
the syntax and naming rules. I tried to find some details on how
people (programmers) name structures, classes (special type of
classes), objects, constructors, destructors, functions,..etc., and
how to navigate between different parts of the code to follow the
implemented logic...but has no luck so far.
Can anyone help me how I should dive into this How you did when you
were a beginner and had faced similar situation I believe, all I need
is some guidance that can save me wondering around the code files.
replies are greatly appreciated.

String::Format problem (VC++ .NET 2003)
&nbsp(210 Views)
I spent many hours on this, googling around and experimenting, and still
nothing.
I wrote an umanaged program (actually various classes), while I was
developing them I used command line to test it.
Now, I decided to make GUI for it, so I created new project: "Windows Forms
Application (.NET)" (I was trying to use something that's not managed (e.g.
MFC, but I learned quickly that I don't actually know how to use MFC
In .NET I was able to quickly create the GUI that looked as I wanted it too
look.
Now my problem is really silly. While I figured out how to convert
System::String to for example std::string, and looks like the other way
around is actually easy, I can't for a love of God make String::Format do
what I want.
Even the examples from MSDN doesn't work when I copy&paste them verbatim!
Here is an example: http://msdn2.microsoft.com/en-us/library/fht0f5be.aspx
In a simple program that has just textbox, button and label, the following
code works:
label1->Text = String::Format(", {0}", textBox1->Text);
But this, doesn't want to:
label1->Text = String::Format(", {0}", 10);
My goal is basically do something like this:
unsigned short int pc = 8000;
label1->Text = String::Format("Address: {0,4:X}", pc);
Anyone has idea what I'm doing wrong
I have also an unrelated question: If I have a managed class (for the
form), and I define inside a pointer to an unmanaged class, is that a good
practice Right now it appears to work fine, but before I had an exception
that the pointer is null (even though I did new on the form's load, and
pointer was used after selecting an option from a menu). I have no idea how
I even fixed it.

A weird problem on structure and union alignment
&nbsp(298 Views)
Please forgive me for cross-posting. I've post this to
microsoft.publoc.vc.mfc. But I can't get any response. Maybe only MFC-
related topics are cared there.
To begin with code:
union XXX
{
double a;
char b;
double c;
};
XXX s;
size_t n1 = sizeof(XXX);
size_t n2 = __alignof(double);
size_t n3 = __alignof(XXX);
double* p1 = &s.a;
char* p2 = &s.b;
double* p3 = &s.c;
XXX* p4 = &s;
Compiler: VS 2005 + SP1
Output:
n1 = 8
n2 = 8 // the largest member in the union is 8-byte aligned!
n3 = 4 // , it should be 4 less than 8
p1 = 0x0012F5B4 // , it is not 8-byte aligned!
p2 = 0x0012F5B4 // ditto
p3 = 0x0012F5B4 // ditto
p4 = 0x0012F5B4 // ditto
Below is a related article copied from the site "The Old New Thing".
Because posting new comments to the original post has been disabled,
so I have to put it here. Please note the first comments to the post
by Roger Lipscombe, He/She says: "the C standard states that they must
be aligned suitably for the largest contained member." However, I
can't find any statement in the C standard, Is that implementation-
defined

Class reference member problem
&nbsp(300 Views)
i have the following situation
class B
{
static B createBobj();
}
Class A
{
func()
{
m_obj = createobj();
}
B& m_obj;
};
Obviously doesn't compile so
In class A i want to hold a reference to an instance of class B
created by the
factory method createBObj. i can't initialise my reference member in
constructor as
class A needs to do some other initialisation before creating instance
of B.
So how to solve this problem

iterator problem
&nbsp(372 Views)
I built a container (without a template), an iterator as a nested class and
a "find"-method:
iterator has a friend relationship with Hash_Map and vice versa.
class Hash_Map
{
iterator find ( value_type ) // Line 6
{
search something.....
return iterator( Param );
}
class iterator : public std:iterator // Line 16
{
iterator( param_type Param ){ do something } //
constructor
various operators and so on.....
};
}
I get the following error message from VS2005:
"Line 6: std::iterator use of class template requires template argument
list"
If i write Line 6 as
iterator find ( value_type )
everything compiles fine.
Why do i have to repeat the template instantiation if i already have done
this on line 16 via the inheritance
books i read about the STL don't need the template instatiation on Line
6.
Did i domething wrong
Greetings
A.Gallus

the diamond problem
&nbsp(207 Views)
I was trying to avoid virtual inheritance recently (performance)
A
/ \
B C
\ /
D
and I wondered if it would be possible for a compiler to arrange the
fields like this
class A
{
stuff
}
class B : virtual public A
{
B subobject
A subobject
}
class C : virtual public A
{
A subobject
C subobject
}
class D : public B, public C
{
B subobject
A subobject
C subobject
}
and so negate the need for virtual inheritance pointers.
would that work i realise for more than 2 base classes you'd need
objects with holes in. a compiler that did this would be pretty
neat, IMO
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

what is the problem with static main()
&nbsp(210 Views)
What is the precise problem for which we cant declare main() as
static. I know there is no reason to do so but still I wish to know
the precise technical problem for which it is disallowed.

cin stream problem.
&nbsp(244 Views)
everybody.
I am trying to protect a customer to enter char instead of number and i
have created the program as below:
int main() {
int number;
do {
cin.clear(ios::failbit||ios::eofbit);
cout > number;
} while(cin.fail());
cout

new problem?
&nbsp(220 Views)
buffer = new char[4535+308];
The above appears to only allocate 4535 bytes. The debugger and
codeguard both show this as only 4535 bytes.
No tricks, just the above seems to do it. bcb studio 2006.
Does anyone else get these results

Rat in a maze problem
&nbsp(216 Views)
Rat in a Maze pblm can be solved using Stack data structure but
shortest possible path can't be found using it(but we can found a
possible path).To find shortest possible path without calculating
length of path which data struc. should be used .plz also describe
algo to solve it.
we can find all possible path using Stack..... then calculate length
of each possible path and find shortest one but its very time and
space consuming soln.

Disclaimer : SolveErrors.com is an independent online IT support service provider company for third party product. The brands, Names, Images, Trademarks, Products & services of third parties mentioned on this website are only for reference and to furnish information. SolveErrors has no affiliation with any of these third-party companies unless such relationship is expressly specified. The services we offer may also be available on the brand owner's website.