|
Nothing should be wrong, but according to the original poster, the data gets corrupted in random positions during the writing. This means that something is wrong with the routine, and I was just curious to find out what this reason is..
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hello all,
I have some questions about inline function, if I have something like this
<br />
class myClass<br />
{<br />
protected:<br />
int i;<br />
<br />
public:<br />
inline Set_I(int val)<br />
{i = val;};<br />
}<br />
<br />
int main()<br />
{<br />
myClass c;<br />
c.Set_I(10);<br />
}<br />
I want to know what will actually happen. Since Set_I() is an inline function, the compiler will replcae the definition of the function in where the function has been invoked. However, in this case the inline is actually accessing the protected member of the class, so what will happen??
Thanks!
Nachi
|
|
|
|
|
nachilau wrote:
However, in this case the inline is actually accessing the protected member of the class, so what will happen??
Exactly the same thing. The protected keyword tells the compiler that the i variable can be accessed by members of myClass or its derivatives. This condition is still true. Whether or not the compiler inlines the member functions makes no difference at all. It is still the same function accessing the same variable.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
nachilau wrote:
compiler will replcae the definition of the function in where the function has been invoked.
No. inline is a suggestion to the compiler, it can choose to ignore it.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
inline is an important keyword, but it must be used as:
1. in h file, but not inside class scope(if so, it is ignored)
2. not in cpp file (if so, it is ignored)
example is
//MyClass.h
class MyClass
{
public int Get();
};
inline
int MyClass::Get(){return 1;}
advantage of inline function is
1.(at least books say) it is faster than normal function.
2.in case of you need to put your code on head file (e.g. craete library)
includeh10
|
|
|
|
|
includeh10 wrote:
public int Get();
};
inline
int MyClass::Get(){return 1;}
2.in case of you need to put your code on head file (e.g. craete library)
In fact, the compiler is trying to inline any function defined in the *.h-file. Regardless of inline or not.
If you want to suggest to inline a function with a body in the *.cpp-file, you add inline before the declaration in the header file.
In any case, you are only giving a suggestion, you can not force the compiler to do the inlining.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
i think u never use inline before.
code above can not be compiled if no keyword inline.
includeh10
|
|
|
|
|
I am just trying to test this API function on Outlooks
SysListView32 control.
ListView_GetItemCount works fine but ListView_GetItemText
crashes Outlook.
void testListView(HWND listView)
{
int count = ListView_GetItemCount(listView);
printf("%d", count);
printf("\r\n");
char text[25];
//LVITEM item;
//memset(&item, 0, sizeof(item));
//item.mask=LVIF_TEXT;
//item.iSubItem=0;
//item.pszText=text;
//item.cchTextMax=25;
//item.iItem=1;
//SendMessage(listView, LVM_GETITEMTEXT, 1, (LPARAM)&item);
ListView_GetItemText(listView, 1, 0, text, 25);
printf(text);
printf("\r\n");
}
jp
|
|
|
|
|
Are you calling this from another application, or from an Outlook addin? It won't work from another application because Outlook will try to write to an area of memory that does not belong to it, causing an access violation.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Yes, from another application.
Is there any way to do it?
I don't want to go the AddIn route.
thanks
|
|
|
|
|
Also, why can I return a RECT successfully?
What is the difference?
GetItemRect works ok??
|
|
|
|
|
Guys,
yet another question.
How do I use global varibales across multiple files.
and where exactly do I define the "extern int count;" ?
lets suppose I have the following
myclass.h
myclass.cpp
mymain.cpp -> this is where the main() program exists.
basically I want my class to update a global variable everytime its called, and then I want to be able to read that variable from my main as well ?
any suggestions? I m trying the "extern" but getting some LINK error saying I have unsolved external symbols.
pls help
Thanks
|
|
|
|
|
A better way to go would be to make a function such as UpdateGlobalVariable that all of the modules can access. It would reside in mymain.cpp and update a variable that is declared there.
a two cent stamp short of going postal.
|
|
|
|
|
Global variables are evil. If you must, then declare it in stdafx.cpp and put your extern in stdafx.h.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
In 99.9999% cases you can avoid global variables. For example, you should declare it in CWinApp class or in MainFrame class. Both of them, have only one instance in the program, so you can access it by AfxGetApp()->theVariable or AfxGetMainWnd()->theVariable .
Robert-Antonio
It's a good luck, when you meet a real fink. Then you get a respect to
normal, mid-honest people."
|
|
|
|
|
True, but you still have the global variable. All you are really doing is moving the global variable around so it isn't a traditional global variable. However, functionally, it still acts like a global variable and thus has most of the exact same problems associated with it.
I think it was Christian that said wrap the global variable in a global function. The good thing about this approach is that it makes it much easier to add some form of locking to the variable.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
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
|
|
|
|