I am overriding OnSaveDocument in my MFC document class to strip out the carriage returns when saving my app's document to a UNIX file system but not when the user is saving a file to a Windows file system.
Is there a way to determine if the lpszPathName in OnSaveDocument(LPCTSTR lpszPathName) is a UNIX or Windows file system?
Note, I want to avoid hard coding server names and I want to avoid overriding the FileSave dialog and forcing the user to select Windows or UNIX.
/** This class build the singleton design pattern. Here you have full control over construction and deconstruction of the object. */ template<class T> class Singleton
[Code]....
I am getting error at the assertion points when i call to the class as follows:
test.cpp: In function ‘int main()’: test.cpp:20:30: error: no matching function for call to ‘func1(std::vector<int>&)’ test.cpp:20:30: note: candidate is: test.cpp:8:45: note: template<class T, class U> std::map<T, T> func1(U) test.cpp:8:45: note: template argument deduction/substitution failed: test.cpp:20:30: note: couldn't deduce template parameter ‘T’
list contains, in order: A, B and C in any order, D, E
I am thinking it is possible with some clever template and polymorphism combos, but maybe not. As a last resort I know how to make it work by storing static type information in each class, but I'd like to avoid that if possible.
This program is incomplete as I am having difficulty creating the function that needs to find the number of perfect scores entered by the user. I have everything but the function complete ,here is my code:
Code: // Write a modular program that accepts at least 10 integer test scores from the user and stores them in an array. // The main should display how many perfect scores were entered (i.e., scores of 100), using a value-returning countPerfect function. // Input validation: Do not accept scores less than 0 or greater than 100.
#include <iostream> using namespace std; int countPerfect(int intArray[], int); // Function prototype
I have a class "Result" with a single template function Set(const std::string& arName, T& val) and a specialization of this function Set<Real>(const std::string& arName, Real& val) where Real is a typedef for double. The class is in a shared library and I use it in my main program. If I do result->Set<GLOBAL::Real>("U", 100.0); the wrong template function is called!
I check this by the output with std::cout.
Maybe it's a problem with the typedef.
If I link the object file of the Result class directly to my main program (no shared library), it works.
Originally I had to create a simple integer palindrome program that looped while the user entered 5 digit inputs (entering -1 stopped the loop). I did this using a conversion to string, reading the length to determine if the length was valid, and then reading the string forward and backwards inside of a while loop. (snippet below)
while( digitsEntered != -1)//Allow user to quit by entering -1 to end the loop { ostringstream convert;//conversion stream convert << digitsEntered;//converted text from number goes in the stream convertedString = convert.str();//store the resulting conversion to convertedString
[Code] ....
The next stage of this program was to do the same thing with strings instead of integers. However, the option to end the loop by entering -1 is still a requirement.
I think the way to do this is to first determining whether the input is a string or an integer, and if it is a string then read it and if it's an integer determine if it's -1. However, whenever I write code to do this, it converts strings to 0 so the string is not stored and cannot be read to determine if it is a palindrome. Is there a way to determine the type of input without converting it into a different type i.e. read string and then keep string or read number and keep number?
Write a program that will prompt a user to enter a single character, the prompting will continue till a sentinel value is entered. For each character entered perform the following tests and print out a relevant message if the character passes the test. Print out a default message if the character does not pass any of the tests.
Tests that should be in program: Punctuation, Upper Case, Digit, White Space.
Sample Run: “A”, “a”, “7”, <tab>, “?”, “$”
So far I have the following code done. The problem is that when I run the program, the first character is correctly identified. However, every character afterwards is defined as a whitespace character.
#include <iostream> #include <cctype> #include <cstring> using namespace std; int main() { char input; char response;
I have part of a class that checks to make sure there is a fault that lasts for 60 seconds. The code below is written several times throughout the class for different subsystems dealing with overcurrent.
// Over Current if (UUV->getCTaps(MOTORCURRPOS_1) > 1.4*UUV->getcurrMode.getMotor().Peak) // The fault { if (motor1Timer == NULL) motor1Timer = time(&timer); else if ( time(&timer) - motor1Timer >= 60) motor1Over = true; } else motor1Timer = NULL;
The timing statement is okay because it works on all of the other fault checkers. It is the if statement that is causing the error I just do not know why.
If I declared that code in a header file I'd be able to call it with an int, float, double or whatever. But where does the actual code get instantiated? Is it effectively inlined?
What I'm wondering is if there'd ever be any scenario for putting such code in a DLL - e.g.
I just tried it and was slightly surprised to find it wouldn't compile. It compiles fine when actually building the DLL but when I try to build something else which uses that DLL I get compiler error C2491 (definition of dllimport function not allowed).
I guess that kinda makes sense if template functions are effectively inlined... or is there some other explanation....
I stumbled upon an unexpected difference between GCC and VisualStudio: Different overloaded functions are called in the following example:
// -------- can assume this is located in 'tool.h' file -------------- // Fwd declaration support foo( const int& ) gets called as expected by both compilers // void foo( const int& n );
template< typename T > void foo( const T& n ) {
[Code] ....
What happens: I expected that by calling bar(1) compiler will notice both versions of foo() and call the best match, in this case foo(const int&). That is not the case.
Note that overloaded foo(const int&) is below bar(). It seems that at that point GCC does not see overloaded version, and happily calls template version. Visual studio on the other hand has no problem finding them both.
If I introduce a forward declaration of foo( const int& ) before bar(), both compilers call that version correctly. Unfortunately, that is not a solution for my problem here.
Template version is part of a library while overloaded is part of the user code. Both would be located in different (header) files and I would not like to impose #include order to the users or to be dependant on it.
I'm fairly new to C++ and have begun working with pointers. I wish to create am array called sigmaf_point that reads data from a text file. I have managed to get that working, but when it comes to using this pointer I come across some problems. The array is created as such:
I then create a coordinate system inside the main file, as the program I am writing is about modelling the movement of atoms, which requires you to know the coordinates:
Code: int main(); double **coords_fluid = new double*[5000]; for (int i = 0; i < n_atoms_methane; i++) { coords_fluid[i] = new double[4]; }
Now, the problem arises when I want to calculate a new variable as so:
Code: for (int i = 0; i <= n_atoms-1; i++) { sf1=sigmaf_point(coords_fluid[i][3]); }
I get the error C2064: term does not evaluate to a function taking 1 arguments, and a red line under sigmaf_point that says it must be pointer to function type. I am a bit confused about this.
I'm trying to implement a simple template array class, but when i came into the operator< i actually have to use a template :
my code is something like :
template<typename _Type, std::size_t _Size> class array { public :
[Code] ......
but i am having an error of shadows template param 'class _Type' is it w/ the name conflict between the array template parameter and the function template parameter ?
I would like to use my own template type. I have class Fraction that saves fractions, and class Sample(the template class) that arrange fractions in order.
where 'g()' returns an object of the element type. However, the compiler is claiming, no matter how I write a call to the overload, the original template is selected and/or the overload is invalid, depending on the various ways I attempt to write said overload.
Is there a way to detect whether or not a template type has a protected destructor?
I see there is std::is_destructible in C++11, but I can't tell if this will return true or false for the protected case. Also, I'm interested in finding a solution for C++03 as well.
is there a way to have a template class respond to missing stuff in a template type ?
Code: template <typename Type> class MyClass { public: enum { ID = Type::ID }; // revert to 1 if Type::ID doesn't exist. };
If the Type passed to the template has an ID member (required to be an enum or a static const int), use it, if it is missing revert to a default value.
I can use this as a simplified way of configuring how MyClass works, without requiring Type to explicitely needing to define what it doesn't care about.
It needs to be resolved at compiletime, as it determines the number of elements in member array variables.