c++

c++: overloading + operator for a sparse matrix

void add(sparseMatrix<T> &b, sparseMatrix<T> &c); // c is output sparseMatrix<T> operator+(sparseMatrix<T> &b); I'm creating a sparse matrix which is made up of an arrayList of singly linked lists of matrix terms (matrix terms contain the row, column, and value). I'm having trouble overloading the + operator. I have an add method whic...

volatile and double confusion

int x = 2; volatile int y = 2; const int z = x/y; int main(){ int x = 2 + 3; double d = 7 / 3; } I have three questions here: Firstly, can the compiler calculate the value of the 'z' at compile time to be 1 in this case? Secondly, I observed that the compiler does not generate assembly instructions for adding 2 and 3 to in...

How to export pure virtual functions from a DLL in C++?

Hello, I am having a strange problem that no pure virtual function is exporting from a DLL. DLL compiles and outputs as .dll file to the directory . But it doesn't produce .lib file. If I give definition and it no longer remians as pure virtual, after that happily it creates .lib file. I need to implement factory pattern for which I n...

Managing C++ project - file layout, dependencies and version control

Hi community, I have recently started a new C++ project and I intend to make it cross-platform in time. I haven't had much experience with C++ projects before so the first thing that bothers me is that default Visual Studio file layout setup. I tried reading-up the Net on this subject but the info just seems rare and conflicting, so I s...

Templates in c++

Hello, I've some problem with using templates: myclass.h #ifndef MYCLASS_H #define MYCLASS_H class myclass { private: public: ~myclass(); myclass(); template<class S> void login(S login, S pass); }; #endif // MYCLASS_H myclass.cpp #include "myclass.h" #include "../additional_func.h" // for connect(QString,QS...

overloading of the operator++()

How can I overload operator++ in two different ways (for a++ and ++a)? ...

Packing 32bit floats into 30 bits (c++)

Hi all. Here are the goals I'm trying to achieve: I need to pack 32 bit IEEE floats into 30 bits. I want to do this by decreasing the size of mantissa by 2 bits. The operation itself should be as fast as possible. I'm aware that some precision will be lost, and this is acceptable. It would be an advantage, if this operation would not r...

C++ Does not name to a type

This might be an easy question, but I cannot figure out why the compiler it's giving me this error. I have two classes. Agent and Environment. WHen I try to add an object of type Agent in my Environment class I get Agent does not name to a type error. I am including Agent.h in my Environment.h class #ifndef AGENT_H_INCLUDED #define AGE...

Returning a type of an object;

Is it possible to return type of an object? For example I would like to have construct like this: //pseudocode template<class T> void f(int value) { //depends on type T different action can be taken } template<class T> type getType(T obj) { return (type of obj); } and then in main: f<getType(Object)>(value); ...

C++ vs Python precision

Trying out a problem of finding the first k digits of a num^num I wrote the same program in C++ and Python C++ long double intpart,num,f_digit,k; cin>>num>>k; f_digit= pow(10.0,modf(num*log10(num),&intpart)+k-1); cout<<f_digit; Python (a,b) = modf(num*log10(num)) f_digits = pow(10,b+k-1) print f_digits Input 19423474 9 Output...

How to query HTML with x XPath expression in C++?

I have a webbrowser and I use DocumentComplete to read the current document from the WebBrowser (as IHTMLDocument2). What's the easiest way to run xpath queries in that html doc? I am looking for something easy to use and lightweight. I am using Visual Studio C++ 2010. ...

Template argument deduction error

template <typename T> void foo(int i) { //nothing inside } int main() { foo(5); //fails foo<int>(5); //works } Why does foo(5) fail but foo< int >(5) work? ...

How to store a concatenation of ints and characters in a char*?

I have some integers, let's say one two and three. I wish to create a string such as char* example = "There are " + one + " bottles of water on " + two + " shelves in room number " + three + "\n".` This doesn't work in C/C++. How can I store that type of value in a char*? ...

Nested Classes C++ static inner methods (Xml parsing and trying to populate vector with values)

So this is what I am trying to accomplish. I am trying to use a sax parser to parse some XML. it looks like I need to call all their methods as statics. So if I want to pass a value back from say startElement it is static void startElement. Which brings me to my example code. I have been pulling my hair on how to update a value in a Nes...

Constructors order

#include <iostream> class A { public: A() { std::cout << " A ctor" << std::endl; } A(int i) { std::cout << " A ctor i" << std::endl; } ~A() { std::cout << " A dtor" << std::endl; } }; class B: public A { public: B() : A () { std::cout << " B ctor" << std::endl; } ~B() { std::cout << " B dtor" << std::endl; } }; class ...

Why does this go into an infinite loop?

Okay, so I'm trying to create a list of he folders, and sub-folders and their files, but right now it doesn't print anything, and seems to be going into an infinite loop. Any idea why? //infinate loop start for(int j = 0; j < (int) dirs[i].folders.size(); j++){ dirs.push_back(Directory(dirs[i].folders[j])); ...

C++, why is array=ptr legal?

Recently i saw this piece of code. Shouldnt this line be a compile error?char arr[4]="Abc"; What happens here? Is arr a pointer? is the char* copied into an array on stack? is this legal in all version of C++ (and what about C?). I tested and seen this works in VS and code pad which i believe uses gcc -edit- Just for fun I tried replac...

How can I generate a directory tree from a root folder and all it's sub folders?

okay, so I'm trying to get a directory of folders and sub folders, but it just goes into a infinite loop. What is a better way to create a directory of folders and sub-folders? Cause I really have no idea. this is my code so far: #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <errno.h> #include <vector> #incl...

Networking with C++

Hey, I'm a newcomer to using C++ but have got a general Idea of its syntax and useability. I want to learn how to communicate over networks through C++ programming though but I can't seem to find any tutorials for C++ specifically. Does anyone know any good resources to learn about networking with C++ or what I should start with? Thanks...

Problem with const array changing c++

Hi, I have this code that tries to protect the user from array boundary errors. I don't get why this will compile, tho i've declared the array to be const, therefore, i'm suppose to get a compilation error! thanks a lot. /************ file: SafeAccessArray.h ********************/ template<typename T> class SafeAccessArray { private: i...