|
int count = 0;
void someFunc1()
{
count++;
}
extern int count;
void someFunc2()
{
count++;
}
By the way, does anyone know how to get codeproject to retain indentation?
|
|
|
|
|
Hello, everyone,
In my project, I used CStaticLink class to change the static text to url style text. It works fine in different dialog boxes. But it is not working good in a CPropertyPage dialog box. The text is not changed to blue color and not underscored, but the link is still working good. I think the problem is from the second parameter *CWnd (in my code, I used "this"), but I cannot figure out what should it be.
What do I need to do to make it work?
Thanks a lot in advance.
Bin
|
|
|
|
|
Hi all!
In my application I'm reading from a console and what is read is written in an edit box, but I need to append the new text so the prior text does not disappear. I normally write
<br />
m_strText=read_text;<br />
but this erases prior text in the Edit Box.
Any ideas?
Thank you in advance!
|
|
|
|
|
very crude:
m_text = GetDlgItemText(IDC_MYEDITBOX);
m_text += new_console_text;
SetDlgItemText(IDC_MYEDITBOX,m_text);
"there is no spoon" biz stuff about me
|
|
|
|
|
I'm novice and would appreciate if I can get a sample/idea on how to accomplish this or sources where I can get oriented:
I need to define 4 classes, each containing its attributes and methods.
say, class a, b, c and d.
What do I have to do in my class declaration so that class d can
publicly overload class a and class b? (class inheritance?)
-How do I access the "private" instances (fields) in class a (a1 or a2) from class d?
-How do I access the member functions of class a in class d?
class a // Csamplea
{
private:
int a1;
int a2;
public:
a(int x, int y);
// default constructor
}
class b // Csampleb
{
private:
int b1;
int b2;
public:
b(int x, int y);
// default constructor
}
class c
{
private:
int c1;
int c2;
public:
c(int x, int y);
// default constructor
}
class d
{
private:
int d1;
int d2;
public:
d(int x, int y);
// default constructor
}
// class implementation
a::a(int x, int y)
{
a1 = x;
a2 = y;
}
// class implementation
b::b(int x, int y)
{
b1 = x;
b2 = y;
}
// class implementation
c::c(int x, int y)
{
c1 = x;
c2 = y;
}
// class implementation
d: (int x, int y)
{
d1 = x;
d2 = y;
// need to update a1, a2
}
Before hand, I want to thank you for any suggestions/ideas.
Thank you again,
Reni
Reni
|
|
|
|
|
beamer_2020 wrote:
How do I access the "private" instances (fields) in class a (a1 or a2) from class d?
You can't, only protected variables and methods are visible to a derived class, that's why we have protected and private.
beamer_2020 wrote:
How do I access the member functions of class a in class d?
So long as they are not private, you can just call them, or use this-> if you want to be explicit about where they are coming from.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian,
Thanks for the answer.
I will place the instances in "public".
Thanks again,
Reni
Reni
|
|
|
|
|
If they were private, they should probably be protected. Don't make anything public unless it makes absolute sense to do so, private or protected should be your default.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian,
Thanks again for your advice.
This is not for a project but for me to learn how sharing can be done within classes.
I also think I should be able to use Classes with Inheritance.
I will play with them. Thanks again.
Reni
|
|
|
|
|
no worries. I guessed you were doing this to learn, which is why I'm trying to cover some best practice stuff, so you learn how to do things *well*. Good luck
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian,
Thanks again.
I agree with you. Making the instances public in a class is kind of "ugly".
I will be testing inherited classes.
Thanks,
Reni
|
|
|
|
|
beamer_2020 wrote:
What do I have to do
How do I
The best suggestion I can give you is that you read the introductory chapters of the C++ book assigned by the instructor. If you have specific questions, you'll find the CP community will be happy to help you. But don't expect a CP member to do your homework for you.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi,
I wasn't expecting anyone to write code for me. I want to thank you for taking the time to reply.
Regards,
Reni
Renato
|
|
|
|
|
Now I feel bad for my reply which appears harsher than I intended it to be. Sorry.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi,
Thanks again for your reply.
This is not for a school project. I'm just playing around with "classes" and wanted to experiment with sharing the instances (fields) between classes.
I replied to Christian and mentioned that I will probably try using "classes with inheritance". <class_specifier> <derived_class_name> : < base_class_name { additional members> };
Unfortunately some of the C++ books I have been reading, do not show you "interaction" between different classes at the beginning.
The other things I have seem is to make the instances public BUT it kinds of defects the beauty of C++.
Thanks again and please don't feel bad. I know of many people who want others to do everything for them.
Regards,
Reni
|
|
|
|
|
Hey guys,
I'm having trouble reading an integer from a text file.
for example I have the following stored in a text file
------------ beginning of file------------excluding this line
H
88
------------ end of file------------excluding this line
and there are no spaces after any of the above words, each word is stored in one line.
I have an ifstream object that reads
char charVar;
int intVar;
inFile.read(reinterpret_cast<char*>(&charVar),sizeof(char));
cout <<"char value is : "<<charvar ;
infile.read(reinterpret_cast<char*="">(intVar),sizeof(int));
cout <<"int Var is : "<
|
|
|
|
|
The number is stored in the file as text, so you have to read it in as text then transalte it into a number using atoi() ect.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Per MSDN, read() reads the number of bytes specified by the second parameter. In this case, it reads 1 byte into charVar , but leaves the CRLF characters in the stream for the next call to read() . I think you need to use getline() instead.
LudaLuda wrote:
and I have to use the ios::binay method to open the file,
Why? From what you've shown, binary mode is not necessary.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
okey guys I got that part to work.
Now I have another problem.
how do I move the pointer so that it points to the beginning of the next record location in the file. I have several records in the file.
|
|
|
|
|
seekp(...);
seekg(...);
Maxwell Chen
|
|
|
|
|
LudaLuda wrote:
how do I move the pointer so that it points to the beginning of the next record location in the file. I have several records in the file.
That all depends on what a "record" is.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I have the following code:
TCHAR * ptszVersionInfo = _T(""); //Executes OK
ptszVersionInfo = new TCHAR[10]; //Executes OK
delete ptszVersionInfo; //Executes OK
ptszVersionInfo = _T("Anton"); //Executes OK
delete ptszVersionInfo; //Weird erro. From debug assert.It basically says there is an error with _CrtIsValidHeapPointer.
Now how come. (I am not very good with string allocation ).
|
|
|
|
|
HAHAHA_NEXT wrote:
_T("Anton"); is a pointer to STATIC memory, u can't free it!
HAHAHA_NEXT wrote:
ptszVersionInfo = new TCHAR[10]; //Executes OK
delete ptszVersionInfo; //Executes OK this would rather be delete [] ptszVersionInfo;
Don't try it, just do it!
|
|
|
|
|
Is there a way i can allocate _T("Anton") Into a dynamic memory ? because my code is all mixed up. (I allocate the string using both methods).
|
|
|
|
|
HAHAHA_NEXT wrote:
Is there a way i can allocate _T("Anton") Into a dynamic memory ?
This does not quite make sense, but I think what you want is:
TCHAR *p = new TCHAR[6];
_tcscpy(p, _T("Anton"));
...
delete [] p;
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|