I am working with a basic C++ program to determine the area and perimeter of a rectangle. My program works fine for whole numbers but falls apart when I use any number with a decimal. I get the impression that I am leaving something out, but since I'm a complete beginner, I have no idea what.
Below is the source:
#include <iostream>
...
I want to know, in c++, when does the initialization of objects take place?
Is it at the compile time or link time?
For ex:
//file1.cpp
extern int i;
int j=5;
//file2.cpp ( link with file1.cpp)
extern j;
int i=10;
Now, what does compiler do : according to me, it allocates storage for variables.
Now I want to know :
does it also p...
Hello
i am designing a front end for Festival TTS using it's C++ API
Everything is working fine in my programme but i have a problem that i am giving a drop down
option to user to select other languages when user select a language from drop down then
festival tts shows a message on console saying:
SIOD:ran out of storage
This mes...
I got the following code, wishing to wrap a group of strings nicely in a namespace:
namespace msgs {
const int arr_sz = 3;
const char *msg[arr_sz] = {"blank", "blank", "blank" };
msg[0] = "Welcome, bla bla string 1!\n";
msg[1] = "Alright, bla bla bla..";
msg[2] = "etc.";
}
The code inside works nicely inside a f...
I have a String class and I want to overload + to add two String* pointers.
something like this doesn't work:
String* operator+(String* s1, String* s2);
Is there any way to avoid passing by reference.
Consider this example:
String* s1 = new String("Hello");
String* s2 = new String("World");
String* s3 = s1 + s2;
I need this kind o...
Hello,
I think everyone has experience working with a code like the following:
void fun(Type1&);
void fun(Type2&);
vector<Type1> vec;
for_each(vec.begin(), vec.end(), fun);
Of course that won't compile, because it's not clear which function to be passed. And what's your commonly-used solution to the problem?
I know this will w...
I'm using Valgrind --tool=drd to check my application that uses Boost::thread.
Basically, the application populates a set of "Book" values with "Kehai" values based on inputs through a socket connection.
On a seperate thread, a user can connect and get the books send to them.
Its fairly simple, so i figured using a boost::mutex::scope...
I have a class like this:
class A {
...private functions, variables, etc...
public:
...some public functions and variables...
A operator * (double);
A operator / (double);
A operator * (A);
...and lots of other operators
}
However, I want to also be able to do stuff like 2 * A instead of only being allowed to ...
Let say I have a object. I'm assigning that to an integer.
MyClass obj1 = 100;//Not valid
Let's say, I have a parameterized constructor which accepts an integer.
MyClass(int Num)
{
// .. do whatever..
}
MyClass obj1 = 100;//Now, its valid
Likewise on any circumstance, does the vice-versa becomes valid?!.
eg) int Number = obj...
I`m having problems converting a char array read from file to an int array. Maybe someone can help me. This is my code:
char vectorPatron[67];
int iPatrones[67];
archivo = fopen("1_0.txt", "r");
for(i=0;i<67;i++){
fscanf(archivo, "%c", &vectorPatron[i]);
printf("%c",vectorPatron[i]);
}
fclose(archivo);
for(i=0;i<67;i++){
iPa...
I was reading about SIOF from a book and it gave an example :
//file1.cpp
extern int y;
int x=y+1;
//file2.cpp
extern int x;
int y=x+1;
Now My question is :
In above code..will following things happen ?
1. while compiling file1.cpp, compiler leaves y as it is i.e doesn't allocate storage for it.
2. compiler allocates storage for ...
I found similar topic:
http://stackoverflow.com/questions/56347/iterators-in-c-stl-vs-java-is-there-a-conceptual-difference
Which basically deals with Java iterator (which is similar to C#) being unable to going backward.
So here I would like to focus on limits -- in C++ iterator does not know its limit, you have by yourself compare th...
I have a struct like this
typedef struct _somestruct {
int a;
int b;
}SOMESTRUCT,*LPSOMESTRUCT;
I am creating an object for the struct and trying to print it's address like this
int main()
{
LPSOMESTRUCT val = (LPSOMESTRUCT)malloc(sizeof(SOMESTRUCT));
printf("0%x\n", val);
return 0;
}
..and I get this warning
...
I have a function which does the following:
When the function is called and passed a true bool value, it sets a static bool value to true
When the function is called and passed a string, if the static bool value is set to true, it will do something with that string
Here is my concern -- will a static variable remain the same between ...
Hi,
I got a C++ program (source) that is said to work in parallel. However, if I compile it (I am using Ubuntu 10.04 and g++ 4.4.3) with g++ and run it, one of my two CPU cores gets full load while the other is doing "nothing".
So I spoke to the one who gave me the program. I was told that I had to set specific flags for g++ in order t...
In my application I have quite some void-pointers (this is because of historical reasons, application was originally written in pure C). In one of my modules I know that the void-pointers points to instances of classes that could inherit from a known base class, but I cannot be 100% sure of it. Therefore, doing a dynamic_cast on the vo...
I subclassed QGraphicsItem and reimplemented paint.
In paint I wrote something like this for labeling the item:
painter->drawText("Test",10,40);
After some time I think It may be useful to handle labeling with seperate item. So I wrote something like this.
QGraphicsTextItem *label = new QGraphicsTextItem("TEST",this);
setPos(10,40);...
Hi,
I'm looking for some advice on the best approach to synchronising access to properties of an object in C++. The application has an internal cache of objects which have 10 properties. These objects are to be requested in sets which can then have their properties modified and be re-saved. They can be accessed by 2-4 threads at any giv...
Hi,
I am using Qt 4.5 in windows XP. I know we have to use Q_OBJECT macro for signal - slot connection mechanism. But besides that, is there are any other reasons to use the Q_OBJECT macro? I recently come to know that for some other meta-object features we require the Q_OBJECT declaration. What are those features beside the Signal-slot...
Hello!,
I know how to compile C and C++ Source files using GCC and CC in the terminal, however i would like to know if its safe to include passwords in these files, once compiled.
For example.. i check user input for a certain password e.g 123, but it appears compiled C/C++ programs is possible to be decompiled.
Is there anyway to com...