I have a template matrix class class defined in a header called "Matrix.h".
Certain matrices are used repeatedly in my program. I thought that I would define these in the "Matrix.h" header file, like so:
const Matrix<GLfloat> B_SPLINE_TO_BEZIER_MATRIX(4, 4, values);
When I do this g++ complains that I redefined the constant in questi...
I'm getting compile error in this code
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
void main(int argc,char *argv[])
{
int i;
for(i = 0;i<10;i++)
fprintf(cout,"%d\n",i);
fprintf(cout,"abc:\n");
string s;
cin>>s;
if(s == "resum...
When do you use each inheritance?
class Base{};
class Derived: protected Base{};
class Derived2: public Base{};
My case:
I have class called Snapshot which only contains GetXXX methods. It is a light-weight classed used to store current state of the Value class. I also use it for recovery, keeping instances of this class long after ...
I am new to inter process communication and need some help. I want to be able to send a string from a C++ program to a C# program. My problem is that the resultant string is gibberish. Here is my code:
Sending program (C++):
void transmitState(char* myStr)
{
HWND hWnd = ::FindWindow(NULL, _T("myApp v.1.0"));
if (hWnd)
{...
Why is virtual behavior being prevented?
class MyClass
{
//........
virtual double GetX();
virtual double GetSomethingElse();
virtual double GetT();
virtual double GetRR();
//........
};
class Processor
{
private:
typedef double (MyClass::*MemFuncGetter)();
...
I wrote a simple program that reads the characters from external device (bar code scanner) from serial port (/dev/ttyS1) and feeds it to the currently active window (using XSendEvent).
Program works fine on faster computers, but on slow ones the situation happens (very often) that characters don't get received in the same order they wer...
Hello all,
I'm not new to programming, but after working in Java I'm coming back to C++ and am a little confused about class variables that aren't pointers. Given the following code:
#include <iostream>
#include <map>
using namespace std;
class Foo {
public:
Foo() {
bars[0] = new Bar;
bars[0]-...
I'm trying to build a function that accepts an array in the following manner:
int inCommon = findCommon({54,56,2,10}, 4);
int findCommon(int nums[], int len){
for(int i=0; i<len; i++) cout<<nums[i]<<endl;
return 1;
}
Note, that's not actually what my function does, but I do loop through the array. I'm just trying to determine if...
I am not sure if the question is already addressed. I was checking the one of the Stack overflow function and got this doubt.
Lets check the code first:
#include <string>
#include <map>
#include <iostream.h>
class MyClass
{
public:
virtual int Func()
{
return 0;
}
int Func2()
{
return 0;
}
};
cla...
If you are using a template in C++ that takes an integer value as a parameter, are there any requirements on an integer variable used as the parameter that are different than if the variable was used as a parameter in a function call?
This is a follow-up to question here . I specifically want to address if there is a difference WRT v...
I'm looking for an easy-to-use macro for calling a function only once for a specific value. For example:
void foo( Object* obj )
{
// Print out the name of each object only once
DO_ONCE( obj, printf("This gets printed only once per object! %s\n",obj->GetName()) );
}
Then
Object obj1("obj1Name"),obj2("obj2Name");
foo(&obj1);
foo...
I have a problem I don't really understand. I have a class Node.
template<class T>
class node {
protected:
T _data;
public:
node(T data);
};
This is in "node.h" file. In "node.cpp" file, there is this constructor:
#include "node.h"
template<class T>
node<T>::node (T data) {
_data = data;
}
While the compiler finds no ...
Hi All,
Can you tell me why the following code is giving me the following error - call of overloaded "C(int)" is ambiguous
I would think that since C(char x) is private, only the C(float) ctor is visible from outside and that should be called by converting int to float.
But that's not the case.
class C
{
C(char x)
{
}
p...
Is there a pattern where I can inherit enum from another enum in C++??
something like that:
enum eBase
{
one=1, two, three
};
enum eDerived: public Base
{
four=4, five, six
};
...
I prefer two ways:
void copyVecFast(const vec<int>& original)
{
vector<int> newVec;
newVec.reserve(original.size());
copy(original.begin(),original.end(),back_inserter(newVec));
}
void copyVecFast(vec<int>& original)
{
vector<int> newVec;
newVec.swap(original);
}
How do you do it?
...
I am trying to improve my embedded C/C++ development on ARM architecture. I have recently moved from 68K development to ARM and wanted to use some of my spare time to dig into the platform and learn the best practices especially on developing for mobile platforms.
Preferably 32bit architecture will be helpful with supporting development...
I've seen some code, as well as some errors generated from my compiler that have a '**' token before the variable (eg **variablename unreferenced-- or something, I can't recall exactly offhand). I'm fairly certain this is related to pointers, if I had to guess it looks like it's trying to dereference twice. '**' is fairly ungoogleable....
I have a need to be able to have a super class execute callbacks defined by a class that inherits from it. I am relatively new to C++ and from what I can tell it looks like the subject of member-function-pointers is a very murky area.
I have seen answers to questions and random blog posts that discuss all sorts of things, but I am not s...
Is there an easy way to use multiple folders in a project with Visual Studio? It has "filters" which look like folders, but it would be really nice to be able to make folders and insert files in them inside VS. Is there an add-in or secret option to enable this behavior?
...
How to write global keyboard hook in Ubuntu (Linux) (like Hook for Windows)
In C/C++ or Python
...