I understand the meaning of 'this', but I can't see the use case of it.
For the following example, I should teach the compiler if the parameter is the same as member variable, and I need this pointer.
#include <iostream>
using namespace std;
class AAA {
int x;
public:
int hello(int x) { this->x = x;}
int hello2(int y) {x...
I have been working on this source code, but nothing seems to go right. A revised source code would be extremely appreciated, or at least a visual solution to my errors.
Here is the following problem: Write a program that reads three edges for a triangle and determines whether the input is valid. The input is valid if the sum of any tw...
I know OpenGL is cross-platform and runs across Windows and Mac, but what other marketable products support it along with OpenGL ES? I'm just curious of its current market. Thanks!
...
I know we can use
perror()
in C to print errors. I was just wondering if there is a C++ alternative to this, or whether I have to include this (and therefore stdio.h) in my program. I am trying to avoid as many C functions as possible.
Thanks!
...
I am working to compile some code to WinCE from Win32. It seems that process.h is not in the SDK. What can I use to replace the mutex and thread functions?
...
Hello:
I have my own implementation of smart pointer which uses reference counting as ownership mechanism (Note: I have tested it and it has no bugs).
Following is my code flow.
Create Object and create Smart pointer to the object
Call function which has following defination : void Func(void* param) (Note: This function run in diff...
I have:
const unsigned int hash_1 = 0xaf019b0c;
const unsigned int hash_2 = 0xf864e55c;
const unsigned int hash_3 = 0xfaea8ed5;
Hashes come from an automatically generated header. These hashes are indirectly associated with tags 1, 2, 3. The tags are associated with classes through a simple compile-time generated id. That way I can ...
I have the following class:
class Stack {
struct Link {
void* data;
Link* next;
void initialize(void* dat, Link* nxt);
}* head;
public:
void initialize();
void push(void* dat);
void* peek();
void* pop();
void cleanup();
};
The pop method is:
void* Stack::pop() {
if(head == 0) return 0;
void* result = hea...
#include <iostream>
#include <string>
#include <boost/bind.hpp>
void foo(std::string const& dummy)
{
std::cout << "Yo: " << dummy << std::endl;
}
int main()
{
int* test;
std::string bar("platypus");
(boost::bind(&foo, bar))(test, test, test, test, test, test, test, test);
}
When run, it prints out, "Yo: platypus." It...
I will be creating a series of projects set up to build COM objects. I attempting to create a property sheet (.vsprops file) which will set up the builds for each project. One of the things I am doing with the properties file is customizing the location and names of the files created by the MIDL compiler. Here's the code I use for thi...
I am currently building a rather large application, using cmake to generate cross platform build scripts. During this process of putting together the cmake build scripts, I have discovered the pain of gcc link line ordering.
The basic issues is that including static libraries in the wrong order leads to unused library symbols being thro...
Please look at the following C++0x lambda related code:
typedef uint64_t (*WEIGHT_FUNC)(void* param);
typedef std::map<std::string, WEIGHT_FUNC> CallbackTable;
CallbackTable table;
table["rand_weight"] = [](void* param) -> uint64_t
{
return (rand() % 100 + 1);
};
I got an error (in Visual Studio 2010) that the lambda couldn't be co...
Hi everyone Im very new to c++ and may be in over my head on this problem im trying to solve. A good visual explanation and solution to my errors or even better a revised source code is all that I ask of. Thanks to everyone who invest there interest into my question.
Heres the problem:
Design a class named rectangle to represent a rec...
We currently use a hardware driver's DLL for a particular piece of hardware we interface with. However, we also have an old internally developed DLL written with VC++ around 2002 that wraps that DLL for a few core functions. This code has been long lost, and was developed well before I came on the scene. So, it cannot be supported or eve...
I am writing a C++ program that will roll a die and flip a coin. I need to use inheritance and polymorphism. I have my virtual functions set up correctly. In my base class(aRandomNumberGenerator) I have a virtual function generate. In main() I need to have an array of 2 base class pointers to my derived classes(aDie and aCoin). How ...
I serialize "double" data type and get an error though
QDataStream & operator<< ( double f )
operator is defined. Here is the error message:
error: conversion from 'double' to 'const QChar' is ambiguous
Did you meat this situation or understand why it can be like this?
...
What is the efficient way of implementing a queue, inorder to learn how it is implemented?
EDIT:
I looked into stl::queue code inorder to learn abt how it is implemented, but the template code making it difficult to understand. After all there is better efficient way is used than having a linked list.
...
If my application runs out of memory, I would like to re-run it with changed parameters. I have various malloc-s/new-s in various parts of the application, the sizes of which are not known in advance. I see two options:
Track all memory allocations and write a restarting procedure which deallocates all before re-running with changed pa...
Goal here is to merge multiple arrays which are already sorted into a resultant array.
I've written the following solution and wondering if there is a way to improve the solution
/*
Goal is to merge all sorted arrays
*/
void mergeAll(const vector< vector<int> >& listOfIntegers, vector<int>& result)
{
int totalNumbers = listOf...
I would like to see the most elegant STL like extension to the partition algorithm in the
STL:
given a vector of ints, partition the vector so that the positive integers appear
to the front of the negative integers
AND
return a map<int, int> where map[i]=j means that integer at index i is now at j.
Obviously the first part (without th...