•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,732 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,188 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 1843 | Replies: 4
![]() |
•
•
Join Date: Mar 2006
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hi!
I have a class called anItem which is defined something like this :
ok should be enough. Constructor/Destructor are empty.
At another place I use this class as a template for a std::list.
I can add and get items from that list without any problem, UNLESS I do the following.
If I add another Item to the anItem-class, it only works if it is not a CString type.
Examples :
above is OK!
Runtime Error ("Memory could not be read.").
Does any of you have an idea what the problem here is?
I am using MS Visual C++ 6.0; this is used in an MFC application.
Thanks!
I have a class called anItem which is defined something like this :
class anItem
{
CString string1;
CString string2;
long bla1;
long bla2;
}ok should be enough. Constructor/Destructor are empty.
At another place I use this class as a template for a std::list.
std::list<anItem> list;
I can add and get items from that list without any problem, UNLESS I do the following.
If I add another Item to the anItem-class, it only works if it is not a CString type.
Examples :
class anItem
{
CString string1;
CString string2;
char string3[10000]; //new char array
long bla1;
long bla2;
}above is OK!
class anItem
{
CString string1;
CString string2;
CString string3; // new CString
long bla1;
long bla2;
}Runtime Error ("Memory could not be read.").
Does any of you have an idea what the problem here is?
I am using MS Visual C++ 6.0; this is used in an MFC application.
Thanks!
>I have a class called anItem which is defined something like this
I'll assume it's "something" like that rather than exactly like that because that class won't compile (no trailing semicolon) and even if it did would be unusable because all of the data members are private with no way to access them.
>Runtime Error ("Memory could not be read.").
Step through your code, and find out exactly when this happens and what you're doing at the time. Debugging remotely is difficult enough when the problem isn't vague.
I'll assume it's "something" like that rather than exactly like that because that class won't compile (no trailing semicolon) and even if it did would be unusable because all of the data members are private with no way to access them.

>Runtime Error ("Memory could not be read.").
Step through your code, and find out exactly when this happens and what you're doing at the time. Debugging remotely is difficult enough when the problem isn't vague.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: Mar 2006
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
youre right, sorry. here is the actual class :
so what happens is that the app crashes as soon as i compile with the comment removed and CString lspec is an attribute of the class.
Any Ideas anyone??
class DataTreeItem
{
public:
DataTreeItem();
virtual ~DataTreeItem();
CString projectpath;
CString spec;
CString name;
char local[1024];
//CString lspec;
int size;
int type;
long version;
long checkedout;
HTREEITEM treeitem;
IVSSItem * vssitem;
};so what happens is that the app crashes as soon as i compile with the comment removed and CString lspec is an attribute of the class.
Any Ideas anyone??
>so what happens is that the app crashes
Define 'crash'.
>Any Ideas anyone??
No, because you're still not giving enough information. At this point, post a small program that exhibits the problem so that we can debug it personally rather than play twenty questions with you.
Define 'crash'.
>Any Ideas anyone??
No, because you're still not giving enough information. At this point, post a small program that exhibits the problem so that we can debug it personally rather than play twenty questions with you.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
So this doesn't run:
but this does:
It looks like a CString is equivalent to a char*. In that case, you need to allocate memory dynamically for it or use a char array.
Your best bet would be to use a string, from <string>. They automatically resize themselves.
CString bad; bad[999] = 'a';
char good[10000]; good[999] = 'a';
It looks like a CString is equivalent to a char*. In that case, you need to allocate memory dynamically for it or use a char array.
Your best bet would be to use a string, from <string>. They automatically resize themselves.
#include <iostream>
#include <string>
int main(void) {
string name;
std::cout << "Enter your name: ";
std::cin >> name;
std::cout << "Hello, " << name << '!' << std::endl;
return 0;
} dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- XSLT weird problem... [urgent] (RSS, Web Services and SOAP)
- HELP!!! Weird problem... (C++)
- Problem While Processing A String List (C++)
- weird problem : Internet Explorer cannot load all geocities pages (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: Help with Map
- Next Thread: Compiling in Fedora Core 4



Linear Mode