Why do we need both using namespace and include directives in C++ programs ?
For example,
#include <iostream>
using namespace std;
int main() {
cout << "Hello world";
}
Why is it not enough to just have #include or just have "using namespace std"
and get rid of the other ?
(I am think of an analogy with Java, import java.net.* ...
Hello, I'm trying to create proper header files that don't include much other files.
(To keep them clean, to speed up compiling time, ...)
I encountered two problems while doing this:
1 - Forward declaratoin on base classes doesn't work.
class B;
class A : public B
{
// ...
}
2 - Forward declaration on STD classes doesn't work...
I'm still trying to debug a very sneaky memory corruption problem. I came across a section of my code that allocates memory on one thread and deletes it on another.
I have a vague feeling that this is wrong, but I'm not sure why. The threads share the process memory and access to these structures is protected by a mutex, so I think ever...
If I create a file:
test.cpp:
void f(double **a) {
}
int main() {
double var[4][2];
f(var);
}
And then run:
g++ test.cpp -o test
I get
test.cpp: In function `int main()':
test.cpp:8: error: cannot convert `double (*)[2]' to `double**' for argument `1'
to `void f(double**)'
Why is that I can't do this?
Isn't double va...
Hello,
I am writing an application that needs to send data over a network. I have the application completed but there is a problem with sending the data. Every time I send a piece of data, it is cut off after 4 characters and the rest is garbage. The application is a remote keylogger I am writing for a school project, which requires you...
Is this a good way to implement a Finally-like behavior in standard C++?
(Without special pointers)
class Exception : public Exception
{ public: virtual bool isException() { return true; } };
class NoException : public Exception
{ public: bool isException() { return false; } };
Object *myObject = 0;
try
{
// OBJECT CREATIO...
I'm starting work on a huge C++ codebase, and was wondering if someone could suggest good source code comprehension tools.
I usually use doxygen but was curious to see if anything better existed.
Thanks.
...
Hello, I am working on a c++ win32 program that involves a keyboard hook. The application is a win32 project with no user interface whatsoever. I need to keep the application from closing without using causing the hook to not work or use up a bunch of system resources. I used to use a message box but I need the application to be complete...
I need to modify my program to accept Unicode, which may come from any of UTF-8 and the various UTF-16 and UTF-32 encodings. I don't really know much about Unicode (though I've read Joel Spolsky's article and the Wikipedia page).
Right now I'm using an std::istream and reading my input char by char, and then storing (when necessary) in...
I have a weird error in my C++ classes at the moment. I have an ActiveX wrapper class (as part of wxWidgets) that i added a new virtual function to. I have another class that inherits from the ActiveX one (wxIEHtmlWin) however the ActiveX class always calls its own function instead of the one in wxIEHtmlWin which overrides it.
I can't w...
Have a use case where
Class foo {
public:
static std::string make(std::string a) { .. }
}
I want to make foo an abstract base class but obviously make cannot be in this abstract base since virtual functions cannot be static.
Like this
Class foo {
public:
static virtual std::string make (std::string) = 0; //error this cann...
In C++Builder, I wrote the following code (in Button1Click handler), When I run in debug mode, I get the "Int3 DbgBreakPoint" (Stack corrupted?). This doesn't happen for AnsiSting (Maybe reference counting).
WideString boshluq;
boshluq=L" ";
Is this normal? What do you suggest me to fix this code?
...
I was getting on fine reading "C++ From The Ground Up" by Herb Schildt, 3rd edition (2003) finding it explains things a lot clearer than some of the other books available. However it's apparent that many people consider Herb Schildt's books to be full of errors. e.g. see #16 at http://www.faqs.org/faqs/C-faq/learn/. Is this right and wou...
I'm writing a C++ program (compiled with gcc and running on RedHat Linux). The program needs to know at runtime how much space is left on the stack and how much is left in the heap. I realize there may not be a definite answer to this question (about the heap), so alternatively, I could use the amount of memory already allocated from t...
I have a dialog in MFC with a CStatusBar. In a separate thread, I want to change the pane text of status bar. However MFC complains with asserts? How is it done? An example code would be great.
...
Here's a simple question.
I've done plenty of work using both C & C# (2.0) but never anything in C++. What can I expect to be different when learning C++? Will there be any big gotcha's or hurdles I should pay attention too? Does anyone good crash course book/website recommendations for learning C++ for the experienced programmer?
...
Hi
I am trying to send an HTTP request with the contents of a file set as the body of the HTTP request and want to get the response from a server using VC++.
Any help is appreciated. Thanks.
I think I was not very clear with what I wanted to do or I misunderstood the answers. Neways, what I want to accomplish is, one of my web-service...
What do you like to have in the C++ cheat sheet?
...
I know the rule is to NEVER throw one during a destructor, and I understand why. I would not dare do it. But even the C++ Faq Lite says that this rule is good 99% of the time. What is the other 1% that they fail to delve into?
Link to the C++ Faq Lite bullet point on throwing from ~():
...
Hi
This is my first question in this forum, so please bear with me and I hope I'm not violating any rules. I am looking at different ways to model scattered 3d data as a gridded function (over xy support, z=z(x,y)).
Answering another question, coryan was so nice as to mention the method using heat equation to interpolate (approximate) a...