| | |
Apparent flaws in C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
[code]
class A {
A& a;
public:
A(): a(* new A()) {}
};
[code]
There is a huge flaw here and before I compiled this code I was hoping that it will fail to compile, But it didn't. At first I felt like I had a big flaw in C++ as it allowed data member pointers of the same kind in a class, but then I realized the flaw was in that it is a recursive function call, which will form an infinite loop. Apart from recursive functions, which other methods do you ppl know about C++?
class A {
A& a;
public:
A(): a(* new A()) {}
};
[code]
There is a huge flaw here and before I compiled this code I was hoping that it will fail to compile, But it didn't. At first I felt like I had a big flaw in C++ as it allowed data member pointers of the same kind in a class, but then I realized the flaw was in that it is a recursive function call, which will form an infinite loop. Apart from recursive functions, which other methods do you ppl know about C++?
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
0
#3 Nov 9th, 2009
That's a good way of looking at it.. but anyway I was more interested in knowing what other such necessary-to-avoid situations are.. like dynamic memory allocation is another such thing. Well, I'm a beginner as far as C++ programming is concerned(mostly used java) and was curious to know what all things I should be cautious about. Anyway, Java did solve the problem of leaked dynamic memory allocation through its internal junk management but C/C++ are not much safe (ok, smart pointers and std::auto_ptr are alternatives, but still not foolproof)about that. Returning to the original problem, even Java suffers from this risk of falling into infinite loops dues to recursive function calls.
•
•
Join Date: May 2004
Posts: 95
Reputation:
Solved Threads: 9
2
#4 Nov 9th, 2009
•
•
•
•
Returning to the original problem, even Java suffers from this risk of falling into infinite loops dues to recursive function calls.
•
•
•
•
C is designed with the assumption that if the the programmer does something, however strange it seems, it is because he means to do it.
Allowing recursion without this possibility is sort of like inventing a language in which untruthful statements aren't grammatical--a warm, fuzzy thought, but such a thing simply doesn't exist.
Sometimes recursion loops are detectable, but no development environment I've ever worked with has even bothered to try.
The halting problem is at the heart of this issue... I recommend you study it if you haven't seen it already. This version is more entertaining.
--smg
![]() |
Similar Threads
- My program (major flaws in it) (Python)
- Code Snippet: Database Management Program (Java)
- News Story: When is a bug fix not a bug fix? (Apple Hardware)
- News Story: Microsoft Patches Critical Flaws in GDI+ (Network Security)
- News Story: Fewer flaws FUD wars as Microsoft paints misleading picture of Linux security (Novell)
- Find out the flaws in my website (Website Reviews)
- detecting flaws (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: arithmetic calculator
- Next Thread: c or c++ program to excute at a specified time
Views: 245 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






