|
-
June 2nd, 2011, 11:25 AM
#4
Re: Segmentation Fault in FLTK
 Originally Posted by JohnW@Wessex
To illustrate Paul's point, consider this bit of code.
Code:
#include <iostream>
using namespace std;
class C
{
public:
void F1()
{
cout << "F1\n";
}
void F2()
{
cout << "F2\n";
i = 0;
}
private:
int i;
};
int main()
{
C *p_c = 0;
p_c->F1(); // Works!
p_c->F2(); // Crash!
}
'p_c' does not point to a valid object, but as F1 does not access any member variables, it appears to function correctly.
F2, on the other hand, tries to access 'i' and fails.
(Compiled and run under Visual Studio 2008)
Just to add, while "p_c -> F1()" 'works', it is still undefined behavior and may not work in the future.
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|