|
If it get overwritten consistently, stepping through the method is the way to go.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
|
Thanks
|
|
|
|
|
There was a VFETCH macro which basically copied over data from the Mainframe emulated storage to your program the macro had a length however it would append a NULL (CString Style) at the end so even though I specified 4 bytes it put a null at the 5 th byte
The local storage the way it is laid out by the compiler is not the way it’s declared in the function so even though the area the VFETCH macro was using wasn’t declared after the BASSM the compiler laid it out that way and the VFETCH overlaid the 1st byte of BASSM
I fixed this problem but I also moved the BASSM to global storage by making it static
Thanks for all the help
|
|
|
|
|
|
I'm not sure what the others are thinking, but context is important here. You have defined BASSM within process_trace. Once you get to the bottom of process_trace (that little curly brace you step over), that context is lost. From a code point of view, it no longer exists.
From a memory point of view, it BASSM may reference memory that still contains the values you init'd it too, but you cannot depend on that.
Context is key here.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Indeed.
|
|
|
|
|
#include <iostream>
#include <cstring>
using namespace std;
class String{
char *name;
int length;
public:
String(){
length = 0;
name = new char[length + 1];
}
String(char *s)
{
length = strlen(s);
name = new char[length + 1] ;
strcpy(name, s);
}
void display(void){
cout<<name<<endl;
}
void join(String &a, String &b);
};
void String :: join(String &a, String &b){
length = a.length + b.length ;
delete name;
name = new char[length + 1];
strcpy(name, a.name);
strcpy(name, b.name);
};
int main(){
char *first = "Joseph";
String name1(first), name2("Louis "), name3("Lagarange "), s1, s2;
s1.join(name1, name2);
s2.join(s1, name3);
name1.display();
name2.display();
name3.display();
s1.display();
s2.display();
return 0;
}
i should get output :
joseph
louis
lagrange
Joseph Louis
Joseph louis lagrange
but instead i am getting:
Joseph
louis
lagrange
louis
lagrange
|
|
|
|
|
name = new char[length + 1];
strcpy(name, a.name);
strcpy(name, b.name);
You are copying both names to the same place instead of concatenating them using strcat . A better way would be something like:
name = new char[length + 2]; strcpy(name, a.name); strcat(name, " "); strcat(name, b.name);
|
|
|
|
|
|
Your join function is not joining but effectively setting only the second string:
void String :: join(String &a, String &b){
length = a.length + b.length ;
delete name;
name = new char[length + 1];
strcpy(name, a.name);
strcat(name, b.name);
};
cannot convert string literal to (char *) To avoid that message change the constructor to accept a const char* argument:
String(const char *s)
{
length = strlen(s);
name = new char[length + 1] ;
strcpy(name, s);
}
|
|
|
|
|
Thank you sir..
here's the working code
#include <iostream>
#include <cstring>
using namespace std;
class String{
char *name;
int length;
public:
String(){
length = 0;
name = new char[length + 1];
}
String(const char *s)
{
length = strlen(s);
name = new char[length + 1] ;
strcpy(name, s);
}
void display(void){
cout<<name<<endl;
}
void join(String &a, String &b);
};
void String :: join(String &a, String &b){
length = a.length + b.length ;
delete name;
name = new char[length + 1];
strcpy(name, a.name);
strcat(name, b.name);
};
int main(){
const char *first = "Joseph ";
String name1(first), name2("louis "), name3("Lagrange "), s1, s2;
s1.join(name1, name2);
s2.join(s1, name3);
name1.display();
name2.display();
name3.display();
s1.display();
s2.display();
return 0;
}
|
|
|
|
|
Quote: To avoid that message change the constructor to accept a const char* argument:
It worked as you told, but how and why it was giving error when i was simply using char, and how i will know in which conditions to use const char ?
please can you elaborate
|
|
|
|
|
Always use const for pointer and reference parameters when the content is not modified by a function.
You have to use it when passing a string literal because that is by definition const (a "string literal" is a const char* which can't be assigned to a non-const char* ).
|
|
|
|
|
thank you
|
|
|
|
|
|
Tarun Jha wrote: length = a.length + b.length ;
[Trivial] note that this actually should be:
length = a.length + b.length - 1;
(And please add a destructor. As a pure FYI, since I assume this is for learning hence not using std::string, you could use std::unique_ptr for name, avoiding the need for anything but a default destructor.)
|
|
|
|
|
I'm trying to use Boost serialization in a C++ project, and my code has triggered the assertion on line 103 of this file. That's the line
BOOST_ASSERT(false); in the bottom-most function in the file. What kinds of things can cause this failure?
The context is that I have a class called Board, whose serialize() overload starts by trying to serialize the member
std::array<Piece*, 16>m_whiteArmy where Piece is another of my own classes. Trying to serialize m_whiteArmy is what triggers the assert. I've tried putting a breakpoint at the top of Piece's serialize() overload. The assertion triggers before it's reached.
I would include a compileable example, but when I've tried writing a toy program to replicate the problem, the toy program has worked. The two most suspicious things I can think of that my attempts at toy programs haven't replicated are that the Board object I'm trying to serialize is a global, and the project is spread over multiple files. Piece is a base class, and m_whiteArmy stores pointers to derived Piece objects, so maybe it matters which file I use
BOOST_CLASS_EXPORT_GUID to register the derived classes in, and I've chosen the wrong one?
Maybe this is all irrelevant - I have no idea where to begin.
modified 6-Mar-18 4:21am.
|
|
|
|
|
Start by having a look at the full code containing the assert statement:
BOOST_ARCHIVE_DECL(const basic_serializer *)
basic_serializer_map::find(
const boost::serialization::extended_type_info & eti
) const {
const basic_serializer_arg bs(eti);
map_type::const_iterator it;
it = m_map.find(& bs);
if(it == m_map.end()){
BOOST_ASSERT(false);
return 0;
}
return *it;
} The assertion is thrown when the specified element can't be found in the container (see map::find - C++ Reference[^] ). Locate where the find function is called in your code and check the passed argument.
|
|
|
|
|
I found that what displayed when I hovered my cursor over the variable eti just before the assert triggered while debugging contained, among other things, the string "rook". That's the string I had associated with the derived Piece class I would expect the first element of m_whiteArmy to point to an element of using BOOST_CLASS_EXPORT_GUID, so I figured there was something wrong with how I did that association. I tried moving my calls of that macro from the top of the Piece cpp file to the top of the main file, and the assertion has gone away. I wish I knew why this is correct and what I'd done before wasn't, but it least it seems to be working now.
|
|
|
|
|
Hello,
How can I handle double click event on Progress bar?
|
|
|
|
|
What kind of platform: WinForms, WebUI, WPF, ...?
ProgressBar for WinForms supports double-click event.
|
|
|
|
|
For Dialog based.
There are WM_ for double click but not working. Any idea?
|
|
|
|
|
Fedrer wrote: ...but not working. Care to share (the code)?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Try to subclass this control and add the double click notification in the derived class.
|
|
|
|