I want to enforce explicit conversion between structs kind of like native types:
int i1;
i1 = some_float; // this generates a warning
i1 = int(some_float): // this is OK
int i3 = some_float; // this generates a warning
I thought to use an assignment operator and copy constructor to do the same thing, but the behavior is different:
St...
I do receive a shared_ptr from a library call, and pass it and some resource back into the library. The resource can only be deleted when the shared_ptr deletes its pointer:
std::ofstream* out = new std::ofstream();
...
shared_ptr<Lib::SomeClass> writer = Library.createWriter(out);
Library.appendWriter(writer);
The library expects m...
I wanna make a application like this:
this is console for example:
write_number 5
Your number is 5
How do that?
Can someone explain ?
...
I need to draw a system-like cursor that I simply can control the position of.
In other words, I need to draw a transparent image that looks just like the system cursor and I need it to be rendered on top of all other windows.
I've tried multiple approaches, but they all seem to have some downside.
I've figured out that I can load the c...
We are implementing a text field to do numeric entry. We subclass the standard wxTextCtrl. Behavior is that when user decides to edit the value they get a full precision version and it is selected.
First attempt was to override the focus handler so that when the field gets focus the value is shown in full and selected. This works gre...
Hi, I want to take a string,and populate an array with its values. I know the length of the string is 16. I have tried
char *bit_number[16];
bit_number = bin.data();
and
char bit_number[16];
bit_number = bin.data();
I don't understand what String.data() is returning, why can't I assign it directly to an array? I'm getting compiler ...
I've gotten the gist that the following
<T> my_function(...) {
....
}
is preferred by most, compared to:
<T> my_function(...)
{
....
}
Likewise for:
if (...) {
...
}
being preferred over
if (...)
{
...
}
Is this true and if so, why is the former style preferred over the latter?
...
Here is the issue that I'm having with multithreading. The proc needs to be static which means the only way I see that 2 threads can communicate and share data is through the global scope. This does not seem very clean nor does it feel very OO. I know I can create a static proc function in a class but that's still static.
What I'd like ...
Currently i have a program that loads binary data into a stringstream and then pases the data to a fstream like so:
stringstream ss(stringstream::binary | stringstream::in | stringstream::out);
ss.write(data, 512); // Loads data into stream
// Uses a memory block to pass the data between the streams
char* memBlock = new char[512];
ss....
I'm writing porting file-io set of functions from c into a c++ class. "Magic numbers" (unnamed constants) abound.
The functions read a file header which has a number of specific entries whose locations are currently denoted by magic numbers.
I was taught by a veteran programmer a couple years back that using "magic numbers" is inher...
I recent wrote this post:
http://stackoverflow.com/questions/3737138/how-best-to-store-very-large-2d-list-of-floats-in-c-error-handling
Some suggested that I implemented my 2D list-like structure of floats as a vector, others said a deque.
From what I gather vector requires continuous memory, but is hence more efficient. Obviously thi...
Hello,
Is there a more stable implementation for the cotangent function than return 1.0/tan(x);?
...
How to implement casting to a private base class in C++? I don't want to use hacks such as adding a friend etc. Defining public casting operator does not work.
EDIT :
For example I have:
class A {
//base class
}
class AX : private A {
//a child
}
class AY : private A {
//another specialized child
}
class B {
//base class
void do (A...
Number(string binary)
{
int raw_string_int[size];
char raw_string_char[size];
strcpy(raw_string_char,binary.c_str());
printf("Raw String is %s",raw_string_char);
for (int i=0;i<size;i++)
{
raw_string_int[i] = int(raw_string_char[...
Hi,
Can we open a new terminal tab or window from the existing terminal using a makefile or some c file.
If yes how? Thanks in advance for replying.
P.S. I want to do this because first in the terminal I want to run the server file then I want to open the new terminal and there run the file for the client.
From the second terminal I ...
Note: This is a follow up to this question.
I have a "legacy" program which does hundreds of string matches against big chunks of HTML. For example if the HTML matches 1 of 20+ strings, do something. If it matches 1 of 4 other strings, do something else. There are 50-100 groups of these strings to match against these chunks of HTML (usu...
I made the transition from C++ to objective-C a while ago, and am now finding NSLog() tiresome. Instead, still in Objective-C, I would like to be able to write something like
stdout << "The answer is " << 42 << "\n";
(I know that NSLog prints to stderr, I could put up with writing stderr << "Hello world";)
Basically, I just want to...
I have a small C++ program using OpenMP. It works fine on Windows7, Core i7 with VisualStudio 2010. On an iMac with a Core i7 and g++ v4.2.1, the code runs much more slowly using 4 threads than it does with just one. The same 'slower' behavior is exihibited on 2 other Red Hat machines using g++.
Here is the code:
int iHundredMill...
How would I split a string based on another substring in a simple way?
e.g. split on "\r\n"
message1\r\nmessage2
=>
message1
message2
From what I've been able to find both boost::tokenizer and boost::split only operates on single characters.
EDIT:
I'm aware that I could do this by using std::string::find and std::string::substr...
So here i am trying to teach my friend the art of C++. He is no newbie to programming, but his area of expertise is somewhat further away from C++. He knows html, php and java fairly well, but it seems this is of no use when it comes to writing a C++ program. We already went through the basics, talked about pointers and such. He even had...