Hi,
I'm playing around with C++ for the first time in years. Making an app using Qt, with the Qt IDE. I want to make an app to integrate with the Flickr API. I've got to the point where i need to make a call to a URL.
http://flickr.com/services/rest/?method=flickr.people.getInfo&api_key=987654321&auth_token=9765984&api_s...
I saw the following implementation of the operator* as follows:
class Rational {
public:
Rational(int numerator=0, int denominator=1);
...
private:
int n, d; // numerator and denominator
friend const Rational operator*(const Rational& lhs, const Rational& rhs)
{
return Rational(lhs.n * rhs.n...
What is wrong with my code?
template<int E, int F>
class Float
{
friend Float<E, F> operator+ (const Float<E, F> &lhs, const Float<E, F> &rhs);
};
G++ just keeps warning:
float.h:7: warning: friend declaration ‘Float<E, F> operator+(const Float<E, F>&, const Float<E, F>&)’ declares a non-template function
float.h:7: warning: (if th...
Hi,
I have a legacy C++ code which is ported to Android. When calling free on strings, a random crash is occurring. Crash is observed in random places. Is there a tool which can be used to check the memory overruns?
...
Consider this program:
int main()
{
struct test
{
test() { cout << "Hello\n"; }
~test() { cout << "Goodbye\n"; }
void Speak() { cout << "I say!\n"; }
};
test* MyTest = new test;
delete MyTest;
MyTest->Speak();
system("pause");
}
I was expecting a crash, but instead this happened:...
Hi there!
I'm trying to rotate a 2D image using OGL ES. After load it I can move it through the screen but when trying to rotate the image through its center, it has an odd behavior as the rotation center is the lower-left screen corner, not the center of the image itself.
Googling around I've read that I could push the current matrix,...
I have a class that contains a QMap object:
QMap<QString, Connection*> users;
Now, in the following function Foo(), the if clause always returns false but when I iterate through the map, the compared QString, i.e., str1 is present in the keys.
void Foo(QString& str1, QString& str2)
{
if(users.contains(str1))
users[st...
After some trial and a lot of error, I have come to find out that it is not very useful to template operators. As an Example:
class TemplateClass
{
//Generalized template
template<TType>
TType& operator[](const std::string& key)
{
return TType;
}
//Specialized template for int
template<>
int& operator[]<int>(const st...
I am converting code from C to C++. I am currently using the C function, isspace, what is the C++ equivalent when using an ifstream? Specifically while (!isspace(lineBuffer[l]))
id is the first the number (2515, 1676, 279) and name is the set of letters after the first "space" (ABC, XYZ, FOO).
Example NewList.Txt
2515 ABC 23.5 3...
Hello all,
I saw the following code:
class NullClass {
public:
template<class T> operator T*() const { return 0; }
};
const NullClass NULL;
void f(int x);
void f(string *p);
f(NULL); // converts NULL to string*, then calls f(string*)
Q1> I have problems to understand the following statement
template<class T> operator T*() con...
I'm using gcc, which implements enums as 32 bit integers on the architecture I have (don't know in general). If I try to assign an enum value too large, I get
warning: integer overflow in expression
Is there a way to make gcc use 64 bit integers as the underlying integer type? A gcc specific way is fine, although if there's a portabl...
I'm getting this error message from my compiler:
undefined reference to `Pawn::Pawn(Piece::Color)'
This occurs when I do this:
// board[][] contains pointers to Piece objects
board[0][0] = new Pawn(Piece::BLACK);
Here's part of the Pawn class:
// Includes...
#include "piece.h"
// Includes...
class Pawn : public Piece {
public:
...
I am to create a c++ logic game with with the difficulty of 3-10 characters (@#%?) that are produced within a string randomly. The player is to guess the random characters. Once the player has guessed, the message of how many the player guessed right is displayed. I am using the switch command to have the player determine the difficul...
I am using Windows 7 and I have created on the desktop a file named test.txt. How can I access this file using C++? For example, consider following code:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
fstream inout("test.txt", ios::in | ios::out | ios::binar...
Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
If I write the parameter list like that, the compiler will complain that it needs to know the size of the array at compile time. Is there a way to rewrite the parameter list so that I can pass an array with any size to the function?
Edit...
I'm just getting into Test Driven Development with mock objects. I can do it the long way with UnitTest++, but now I want to try to minimize typing, and I'm trying to use AMOP mock framework to do the mocking.
AMOP states:
The main differences between AMOP and other mock object library is that,
users DO NOT need to implement the
...
I have three queries that I'm running through SQLite. These are what I'm running; the first is the table declaration and then the next 3 are the actual queries.
Declaration:
"CREATE TABLE IF NOT EXISTS items (busid INTEGER PRIMARY KEY, ipaddr TEXT, time TEXT DEFAULT (NOW()));"
Queries:
(Works) "INSERT INTO items (time, i...
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(int argc,char *argv){
fstream inout("C:\\Users\\7\\Desktop\\test.txt",ios::in | ios::out | ios::binary);
if (!inout){
cout<<" cannot open input file.\n";
return 1;
}
long e,i,j;
char c1,c2;
e=5;
for (i=0,j=e;i<j;i++,j--){
inout.seekg(i,ios::...
Hello,
I'm using Intel C++ Compiler from within Visual Studio 2008. I was experimenting with the Intel quadruple precision type (_Quad). Everything seems to be working fine, except for the debugging. Visual Studio visualiser is unable to peek into _Quad values.
What's worse, the visualiser is unable to provide the type information abou...
Hello
i have created two classes. One for input reading (through an istream object) and parsing and the other one for processing the output of the parser.
There is one instance of each of those.
I have the parser running in a loop calling istream::get() and then creating commands for the second object based upon the input. These comma...