I've clearly been stuck in Java land for too long... Is it possible to do the C++ equivalent of the following Java code:
interface Foo {}
class Bar implements Foo {}
static List<Foo> getFoo() {
return new LinkedList<Foo>();
}
static List<Bar> getBar() {
return new LinkedList<Bar>();
}
List<? extends Foo> stuff = getBar();
Wher...
I was give a problem to express any number as sum of 4 prime numbers.
Conditions:
Not allowed to use any kind of database.
Maximum execution time : 3 seconds
Numbers only till 100,000
If the splitting is NOT possible, then return -1
What i did :
using the sieve of eratosthenes, i calculated all prime numbers till the specified n...
I know this.
Calling C function from C++:
If my application was in C++ and I had to call functions from a library written in C. Then I would have used
//main.cpp
extern "C" void C_library_function(int x, int y);//prototype
C_library_function(2,4);// directly using it.
This wouldn't mangle the name C_library_function and linker wou...
#include <iostream>
int& foo()
{
int i = 6;
std::cout << &i << std::endl; //Prints the address of i before return
return i;
}
int main()
{
int i = foo();
std::cout << i << std::endl; //Prints the value
std::cout << &i << std::endl; //Prints the address of i after return
}
I know it doesn't return the address o...
I'm having a huge block trying to understand "trees" while making a Tic-Tac-Toe bot. I understand the concept, but I can't figure out to implement them.
Can someone show me an example of how a tree should be generated for such a case? Or a good tutorial on generating trees? I guess the hard part is generating partial trees. I know how ...
Is it 1 Mb of stack per thread? Or is that just CLR threads?
I want to know the memory over head of native windows threads (c++) and CLR threads as view via Task Manager.
Thanks
...
Hello.
I need fast implementation of popular interpolation algorithms. I figured it out that C# in such simple algorithms will be much slower than C++ so i think of writing some native code and using it in my C# GUI.
First of all i run some tests and few operations on 1024x1024x3 matrix took 32ms in C# and 4ms in C++ and that's what i ...
What (if any) are some potential problems with a C++ macro usage like this?
Would an inline function be a more appropriate solution?
#define EVENT_INFO(_format_, ...) CMyEvent::Generate(__FILE__, __LINE__, CMyEvent::EVT_HIGH, _format_, __VA_ARGS__)
void
CMyEvent::Generate(
const char* file, // filename
int ...
Given integer values x and y, C and C++ both return as the quotient q = x/y the floor of the floating point equivalent. I'm interestd in a method of returning the ceiling instead. For example, ceil(10/5) = 2 and ceil(11/5) = 3.
The obvious approach involves something like:
q = x / y;
if (q * y < x) ++q;
This requires an extra compar...
If i have a function api that expects a 14 digit input and returns a 6 digit output. I basically define the input as a const char *. would that be the correct and safe thing to do?
also why would I not want to just do char * which I could but it seems more prudent to use const char * in that case especially since its an api that i am pr...
We have a body of C++ code which is being ported from a RHEL4-based distro to RHEL-5-based.
It used to compile with g++ 3.4.3, and now compiles with g++ 4.1.2.
It turns out that there are local POD variables that are being used uninitialized, which is causing
failures under the new environment -- not surprising, since C++ rules say that ...
hello.
I know I can do this y[i] += f(x[i]) using transform with two input iterators.
however it seems somewhat counterintuitive and more complicated than for loop.
Is there a more natural way to do so using existing algorithm in boost or Stl. I could not find clean equivalent.
here is transform (y = y + a*x):
using boost::lambda;
t...
I'm reviewing for a test, and I am stumped by this question.
Consider the following declarations:
enum CategoryType {HUMANITIES, SOCIALSCIENCE, NATURALSCIENCE};
const int NUMCOURSES = 100;
struct CourseRec
{
string courseName;
int courseNum;
CategoryType courseCategory;
};
typedef CourseRec CourseLis...
I am confused about how to use destructors when I have a std::vector of my class.
So if I create a simple class as follows:
class Test
{
private:
int *big;
public:
Test ()
{
big = new int[10000];
}
~Test ()
{
delete [] big;
}
};
Then in my main function I do the following:
Test tObj = Test();
vector<Test> tVec;
tVec...
Example:
switch( x )
{
case y:
if ( true )
{
break;
}
cout << "Oops";
break;
}
If the switch statement selects y, will Oops be written to the standard output?
- Is break in switch statements a dynamic keyword like continue which can be called under conditions or static like a closing bracket }?
...
If I have the following lines inside a loop:
Type *unite = new Type(newSize);
or
double *array= new double[anySize];
what is the behavior in what concerns to memory if I don't have delete operators inside it? It will be constantly allocating objects and arrays on different memory locations, and therefore memory leaks?
...
I'm trying to send messages to a window that says Ctrl and Up-arrow has been pressed. I've got the basics down, I can send presses of the space key that registeres fine. But I can't seem to get the ctrl+up working.
chosen code snippets:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMess...
whats the logic to find the sum of alternate elements of a two-dimensional matrix.
...
I have a small contest problem in which is given a set of points, in 2D, that form a triangle. This triangle may be subject to an arbitrary rotation, may be subject to an arbitrary translation (both in the 2D plane) and may be subject to a reflection on a mirror, but its dimensions were kept unchanged.
Then, they give me a set of points ...
warning lnk4075:ignoring /editandcontinue due to /opt:icp specification
error lnk2005: initp+misc_invarg already defined in libcmtd.lib(invarg.obj)
i have many more errors lnk2005 all int he libcmt.lib file in the invarg.obj
also
lnk2098:: defaultlib conflicts with use of other libs.
when i had it as debug it was all working
i just...