#include "stdafx.h"
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int nCmdShow)
{
WSADATA ws;
char buf[100];
WSAStartup(0x0101,&ws);
sprintf(buf,"%d.%d",HIBYTE(ws.wVersion),LOBYTE(ws.wVersion));
MessageBox(0,buf,"info",0...
I was experimenting with C++ and found the below code as very strange.
class Foo{
public:
virtual void say_virtual_hi(){
std::cout << "Virtual Hi";
}
void say_hi()
{
std::cout << "Hi";
}
};
int main(int argc, char** argv)
{
Foo* foo = 0;
foo->say_hi(); // works well
foo->say_virtual_hi(); // ...
Assignment Operator in C++ can be made virtual. Why is it required? Can we make other operators virtual too?
...
Normally using a variable in a .cpp file results in the variable being globally available, like this:
.h file:
extern int myGlobal;
void work();
.cpp file:
int myGlobal = 42;
void work(){ myGlobal++; }
When the .cpp file is put in a static library and more than one shared library (DLL) or executable links against the static library, ...
Hi
I basically have this problem: right now, we have a system where it gets a string as input, and it basically says ACTION:.
For each of the actions there is an automatically generated function(Rational Rose GRRR), such as
bouncer_comm.chatMessage("data goes here").sendAt(msg->sapIndex0());
bouncer_comm.askforname().sendAt(msg->sapi...
Just a quick and simple question, but couldn't find it in any documentation.
template <class T>
T* Some_Class<T>::Some_Static_Variable = NULL;
It compiles with g++, but I am not sure if this is valid usage. Is it?
...
Let's say you have a function that modifies a variable.
Should you write it like this: void myfunc(int *a) or like this void myfunc(int &a)?
The former forces you to call the function with myfunc(&b) so the caller is aware that b will be modified, but the latter is shorter and can be called simply with myfunc(b). So which is better to ...
Does anyone have an idea why the ampersand was chosen as the way to denote references in C++?
AFAIK (though I don't have the book near me), Stroustroup didn't explain that choice, which I find a little odd because the same symbol was already used for address-of in C.
...
As (hopefully) we all know, vector<bool> is totally broken and can't be treated as a c array. What is the best way to get this functionality?
So far, the ideas I have thought of are:
Use a vector<char> instead, or
Use a wrapper class and have vector<bool_wrapper>
How do you guys handle this problem? I need the c_array() functionality...
Can someone help me?
I am trying to do something like the following:
#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/stream.hpp>
#include <sstream>
#include <cassert>
namespace io = boost::iostreams;
typedef io::stream<io::tee_device<std::stringstream, std::stringstream> > Tee;
std::stringstream ss1, ss2;
Tee my_split...
Good evening :)
I'm playing around with g++ and makefiles. I've gotten to this point:
foo.h:
#ifndef _FOO_H_
#define _FOO_H_
#include "bar.h"
class foo {
private:
bar something;
public:
bool start();
bool stop();
};
#endif // _FOO_H_
Foo.h is eventually included in my main cpp file so I can set things in motion by cal...
I came across this strange code snippet which compiles fine:
class Car
{
public:
int speed;
};
int main()
{
int Car::*pSpeed = &Car::speed;
return 0;
}
Why does C++ have this pointer to a non-static data member of a class? What is the use of this strange pointer in real code?
...
I have a class with a lot of built-in type members with read/write access. Should I make them public members and provide get/set methods for each one? How about structures?
...
C and C++ allows passing of structure and objects by value to function, although prevents passing arrays by values, why?
...
Hi,
I recently switched to Emacs and still finding my way through it.
I code in C++ and was wondering what tools out there extend Emacs to support code browsing (finding a symbol etc), refactoring and code completion.
I have heard of:
cedet
etags
cscope
But I'm so confused about what I need. Some places say that cedet provides all o...
So, I wrote a bunch of code that accesses elements in an stl vector by index[], but now I need to copy just a chunk of the vector. It looks like vector.insert(pos, first, last) is the function I want... except I only have first and last as ints. Is there any nice way I can get an iterator to these values?
...
I just want to know which is the best way to execute an external command in C++ and how can I grab the output if there is any?
Edit: I Guess I had to tell that I'm a newbie here in this world, so I think I'm gonna need a working example. For example I want to execute a command like:
ls -la
how do I do that?
...
I have these two functions
void set_dram_channel_width(int channel_width){
printf("one\n");
getchar();
}
void set_dram_transaction_granularity(int cacheline_size){
printf("two\n");
getchar();
}
//output:
one
f //my keyboard input
two
one
f //keyboard input
tw...
What is the name of the Command Line Compiler for a C/C++ program that target's Windows Mobile?
I have Visual Studio 2008 Professional installed and I need to be able to compile a program from the command line. I've checked the project properties in Visual Studio and it shows me all of the parameters that are being passed to the comp...
I am currently creating a program in Qt, OpenCv, Mac os X. I have a main window, and then a separate window that is opened. I pass the new window several matrix clones in the constructor:
ImageWindow *imageWin = new ImageWindow(
cvCloneMat(getData->getMasterRawMat(1)),
cvCloneMat(getData->getMasterRawMat(2)),
cvCloneMat(get...