I've got a function which returns an object of type Foo:
Foo getFoo();
I know the following will compile and will work, but why would I ever do it?
const Foo& myFoo = getFoo();
To me, the following is much more readable, and doesn't force me to remember that C++ allows me to assign an r-value to a const reference:
const Foo myFoo ...
For a static Win32 library, how can I detect that any of the "Use MFC" options is set?
i.e.
#ifdef ---BuildingForMFC---
....
#else
...
#endif
...
I think the problem is an access violation but I just can't seem to find it. Here is the function.
// Structure
struct TestScores
{
char Name[40]; // Student name
int Idnum; // Student ID number
double *Tests; // Pointer to an array of test scores
double Average; // Average test score
char Grade; // Course grade...
I want to have a class with a private static data member (a vector that contains all the characters a-z). In java or C#, I can just make a "static constructor" that will run before I make any instances of the class, and sets up the static data members of the class. It only gets run once (as the variables are read only and only need to be...
I have an Arduino application (well actually a library) that has a number of status flags in it - and originally I simply declared them as ints (well uint8_t so 8 bit unsigned chars in this case). But I could have combined them all into one integer and used bitmask operations to set and test the status.
An example of the former:
if (_s...
In the simplest possible terms (I'm an occasional programmer who lacks up-to-date detailed programming knowledge) can someone explain the simplest way to make use of the registry in codegear C++ (2007).
I have a line of code in an old (OLD!) program I wrote which is causing a significant delay in startup...
DLB->Directory=pIniFile->Rea...
Is it possible to write an impure template in C++? That is, a template that will sometimes give a different resulting type or int for the same template parameters. For example, is it possible to write a template Foo<T> where Foo<int>::type is sometimes char and at other times float? Or a template Foo<T> where Foo<double>::my_static_const...
If I wrote an operator == for class Foo (in C++), what happens, exactly? Does it compare each data member against each other?
class Foo
{
private:
int bar;
public:
bool operator==(const Foo other&)
{
return *this == other; //what?
//is this the same as bar == bar?
}
}
...
I know that it's not safe to throw exceptions from destructors, but is it ever unsafe to throw exceptions from constructors?
e.g. what happens for objects that are declared globally? A quick test with gcc and I get
an abort, is that always guaranteed? What solution would you use to cater for that situation?
Are there any situations...
Edit: I'm trying to convert a text file into bytes. I'm not sure if the code is turning it into bytes or not. Here is the link to the header so you can see the as_bytes function.
link
#include "std_lib_facilities.h"
int main()
{
cout << "Enter input file name.\n";
string file;
cin >> file;
ifstream in(file.c_str(), ios...
I am teaching myself C++, and I am learning more of the compsci side of the issue, like data structures. I want to get into game programming (and, as a side effect, windows programming), especially 2d games (at this point, I really want to clone tetris, since that is my favorite game of all time). I do want to do 3d programming, but that...
Is it possible to pass a function pointer as a template argument without using a typedef?
template<class PF>
class STC {
PF old;
PF& ptr;
public:
STC(PF pf, PF& p)
: old(*p), ptr(p)
{
p = pf;
}
~STC() {
ptr = old;
}
};
void foo() {}
void foo2() {}
int main() {
void (*fp)() = foo...
I have an interface class similar to:
class IInterface
{
public:
virtual ~IInterface() {}
virtual methodA() = 0;
virtual methodB() = 0;
};
I then implement the interface:
class AImplementation : public IInterface
{
// etc... implementation here
}
When I use the interface in an application is it better to create ...
I already looked at this topic, but I need the answer flipped around. How would I set the assembly information attributes* in a Win32 DLL?
...
I have a program which gets commands as a string. Each character in the string represents a command. An example of command is given below
OBIPC
O - Open a file
B - Make the text in Bold
I - Make the text in italics
P - Print the text
C - Close the file
My program has to parse this string and do respective job. Each command is exe...
I have created an application that does the following:
Make some calculations, write calculated data to a file - repeat for 500,000 times (over all, write 500,000 files one after the other) - repeat 2 more times (over all, 1.5 mil files were written).
Read data from a file, make some intense calculations with the data from the file - r...
I'm trying to make my child dialog box to be created as a member of the main application class as follows:
class ParentWindow : public CWinApp
{
public:
// Other MFC and user-implemented classes before this line
MiscSettings activeMiscSettings;
public:
ParentWindow();
~ParentWindow();
// Overrides
virtual BOOL Init...
Hello!
How can I iterate over a tuple (using C++0x)? I tried the following, but that doesn't work:
for(int i=0; i<std::tuple_size<T...>::value; ++i)
std::get<i>(my_tuple).do_sth();
Error 1: sorry, unimplemented: cannot expand ‘Listener ...’ into a fixed-length argument list.
Error 2: i cannot appear in a constant expression.
So, ...
Right now I'm writing a program that will determine the value of a hand of cards. five in total. i have a cardHand object. I'm planning to write an object that compares two objects together in order to determine which hand has a higher value. the two objects that will be compared are objects that contain the possible hand values (one pai...
Hello,
I've forced with a possible bug feature of MFC Feature Pack under Windows Vista. It can be easily recreated:
Create a new SDI app using MFC Feature Pack (with Ribbon based interface). You can also add some floating panels if you want;
Do not change anything, just build a Release;
Close the Visual Studio, run the application and...