C++ :: Way To Restrict A Template-capture To Certain Types / Classes
Nov 16, 2014
I was creating a template and I realized that certain data-types/structs/classes would not be applicable to my template.This would cause bugs and errors if used incorrectly. Is there a way to restrict a template-capture to certain types/classes?
View 2 Replies
ADVERTISEMENT
Apr 4, 2015
I have a program to make a contact book. Included below i will post both header files and cpp files of my contact book, my contact class, and my address class. and my main.cpp. The reason address and contact are separate was because my teacher had us do an exercise where we used a header file of someone else's code, and didn't know what the functions actually implemented. But as the project has progressed he gave us the cpp for address.
Main.cpp
#include "Address.h"
#include "ContactBook.h"
#include "Contact.h"
[Code].....
View 9 Replies
View Related
Dec 17, 2012
Is there a way in either Visual Studio 2010 or g++ (any version) to see what classes it instantiates and their code? For example to see if i avoid code bloat when i explicitly instantiate a template for certain types.
View 3 Replies
View Related
Apr 10, 2014
Is there a way to use preprocessing to conditionally return different types in a template. More specifically, is there a way to use preprocessing to block out conditional parts of code for one type verse another?
Example of what I can't get to compile for anything but POD types:
template <class T>returnTypeMatching(string inputName,string typeName) {
if(typeName="string") {
cerr<<"string types matched so returning string '"<< inputName <<"'"<<endl;
return inputName;
[Code] .....
If I switch string to long, the implied conversions let it work. I'm imagining there might be some preprocessing way to hide irrelevant conditions. I mean, this code would cause an error to return a string when T=double, so I get why there is a compiler error. However, is there a way to make that part of the code get hidden in that case when the template is processed when T=double?
View 11 Replies
View Related
May 15, 2013
I want to write a template that combines two type of resources:
class someClasses {
typedef someType ElementType;
} template<class T1,class T2>
class combo {
...
}
And I want to specify my T1 and T2 has the same ElementType, how can I write my combo class to partial specialize the general case so the ElementType check is at compile time?
View 9 Replies
View Related
Jan 24, 2012
I'm trying to make a template class which holds a template list I made. The list consists of template nodes (another template class I made).
My problem is that in some places (not everywhere) the compiler says that I'm trying to access private members of the node's class.
For example, if I define my node like this:
template<class T>
class CoefNode {
private:
T coef;
[Code]....
View 5 Replies
View Related
Aug 12, 2014
class intClass{};
class stringClass{};
template <typename T>
class Mediator {
// bunch of code
};
I want Mediator<int> to declare intClass friend, Mediator<std::string> to declare stringClass friend etc..., without having to redefine the entire specialization
template<>
Mediator<int>::friend intClass;
View 5 Replies
View Related
Aug 17, 2012
I have a template class which defines a few heavy methods. For now, they are defined in the same .h file as the class definition, but i`d like to have them in a separate .cpp file.
A situation i find you describe in the FAQs arises: [URL] ....
Problem: the export keyword has been deprecated in c++0x, if i recall correctly, and has never been implemented in any of the compilers i am using (msvc, gcc).
#Including the the .cpp file after the class definition (as described in the second post of the FAQ) works.
another question: i have methods that dont use any template code. Can i somehow declare them as such? (more of an esthecial question, which would make it easier to distinguish between template and non.template code).
View 6 Replies
View Related
Sep 13, 2013
Let say i have a following scenario:
a function like this.
Code:
template <typename T1>
print (T1 x){
cout << x << "
";
}
How do I prevent user passing a class or a structure or aanoter function to my function print. I mean i know if a wrong thing is passed that i'll get an error eventually but is there a way to explicitly check what has been passed. How is this done usually ?
View 6 Replies
View Related
Mar 11, 2013
class A {
// is abstract
};
class B : public A {
// ...
};
[Code] ....
[Code] ....
main3.cpp: In member function ‘FooB& FooB::operator=(const FooC&)’:
main3.cpp:46:44: error: expected ‘(’ before ‘other’
main3.cpp:46:49: error: no matching function for call to ‘Foo<C>::Foo(const FooC&)’
main3.cpp:46:49: note: candidates are:
main3.cpp:19:2: note: Foo<T>::Foo() [with T = C]
main3.cpp:19:2: note: candidate expects 0 arguments, 1 provided
main3.cpp:16:25: note: Foo<C>::Foo(const Foo<C>&)
main3.cpp:16:25: note: no known conversion for argument 1 from ‘const FooC’ to ‘const Foo<C>&’
Is there any way to make it work?
View 1 Replies
View Related
Jun 14, 2012
I want to create template of of Array in order to have possibility use this template for classes Line and Point.
Code:
// Array.h
// Templated Array class containging Ts
#ifndef Array_H
#define Array_H
template <class T=double> class Array {
[Code] .....
View 10 Replies
View Related
Jan 22, 2014
I have this
Code:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int check_up(char string[]);
int check_low(char string[]);
void to_up(char string[]);
void to_low(char string[]);
[Code] .....
When I compile this I have the following problems: warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'conflicting types in 'to_up' function and to_low function warning: data definition has no type or storage class [enabled by default] into_up function error: unknown type name "word" in line 'printf("All uppercase %s. ", word):;'warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)' 'note: previous declaration of "to_up" was here in function declaration of to_up function
View 7 Replies
View Related
Oct 14, 2013
I have screen scrolling up and running but it keeps going after the background finishes. how do you fix that?
View 4 Replies
View Related
Mar 6, 2015
I'm doing error checks in C and I'd like to know how to restrict the input of a string to 2 letters and if it is exceeded, i'd like to loop and ask for the code to be re-entered.
Code:
for (i = 0; i < code7; i++)
{
printf("Enter number of items: ");
scanf("%d", &item_qty[i]);
[Code].....
View 2 Replies
View Related
Sep 6, 2013
I want to give a try to "restrict" type-qualifier. I have looked for examples on google and I see the format is used: "int * restrict p";
However when I write this I get an error: "p is undeclared"
I am using GNU GCC Compiler with Code::Blocks.
How can I solve this problem. Is it possible me to adapt the compiler to C99 standarts, if I can, will it solve my problem?
View 13 Replies
View Related
Aug 22, 2014
I am trying to write up something to have a user to enter a four digit number. Only four digits, Ex: 0001, 0116, or 9999. There is no getting around the selection 0001 or 0002. I understand if not done correctly, the first three 0's will be ignored.
I've been just playing around with what I have below but I just don't remember how to do it nor can I find a good example online to figure it out. I know it is not correct just typing to try to remember. I am aware that it is gibberish right now, this is just me brainstorming.
int number;
cout<<("Please enter the four digit number(Ex: 0001):
");
cin>> setw(2) >> number;
cout<<)"Please enter four digit date. Two digits for month and two digits for year:
");
cin>> date;
if (number< || number > 30)
cout << "Invalid choice. Try again." << endl;
cin.clear();
View 2 Replies
View Related
Aug 21, 2014
I have one requirement. I have a project lets Say baseProject.vcxproj. It has some header files. Another project lets say dependentProject.vcxproj loads baseProjects's dll and uses some of its header files.
When some other project lets say unrelatedProejct includes the header file from e dependentproject which includes baseproject's header file. It makes to change the include driectory setting of unrelatedproject. How to avoid this.?
baseproject
base.h
{
}
dependentProject
dependent.h
[Code] .....
View 6 Replies
View Related
Oct 22, 2013
I have to write a program for class in which users will be inputting:
start time = startTime
number of minutes = callDuration
so first off, teacher wants us to input time as a floating point number such as 09.00
How do I validate the time so that users cant input i.e. 09.61 for every hour? In other words, so the user cant input minutes 60-99 for every hour.
then, when calculating:
endTime = startTime + callDuration
how would I make endTime display a correct time in such a situation: endTime = 09.45 + 00.30
so that it displays 10.15 not 09.75
View 4 Replies
View Related
Mar 7, 2014
I am writing a small editor for RSL coding, and ive got an external program "3Delight" to compile the code.
Now i want the output from that exe to be captured in a string once the compilation is comlete, but all of the methods ive found online dont seem to work for me. Ive tried using _popen which works if i run a normal command like "dir", but not with the exe.
This is the function ive been using that works with the normal commands
std::string exec(const char* cmd) {
FILE* pipe = _popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
[Code] .....
and this is how i was calling it, but it just returned an empty string, even though the exe printed "Compilation successful"
exec("""%DELIGHT%/bin/shaderdl" "E:/RenderManShaders/TestArea/Source/basicDiffuse.sl"")
View 3 Replies
View Related
Oct 8, 2014
For my class we have to take a screenshot of the program and put it in a word document. How can I accomplish this?
View 2 Replies
View Related
May 5, 2014
I want program to make bitmap from my Window. I also want to do add some additional steps which I will try to add later. But now I want to ask you how to fix the code. For some reason when I debug the code (break on line 73 of capture.cpp) there the pointer pBitmap is 0x00000000 . So how to correct the code to successfully capture Window? Here I give the complete codes:
stdafx.h
Code:
#pragma once
#include "targetver.h"
#include <stdio.h>
[Code].....
Feel free to set correct name of Window on line 17 for FindWindow() function.
PS: The code is remake of script to capture screen, which saved the bitmap to file. This is not what I want because I would be content if I could send (or maybe share!) the bitmap to ahk script which will ask my C++ program for the bitmap.
View 14 Replies
View Related
Jun 7, 2014
i need to capture the console screen and save to a image:)
View 3 Replies
View Related
Jun 18, 2013
I sent 1preample and 4bytes in transmitting side , preample contains only 1 and 0 with 4milliseconds delay, each byte contains 8bits with 2milliseconds delay , if a bit contains 1 it will send 1millisecond high and 1millisecond low signal ,and if a bit contains 0 it will send 2millisecond continuous delay, I have a problem at receiving side how to capture and store the preample and 4byte values in a buffer , i am using ARM processor it will update every 5microsecond ..
View 1 Replies
View Related
Oct 18, 2014
For a ribbon bar with edit controls (CMFCRibbonEdit) I want to handle the mouse scroll events for the edit controls. That is, when the user clicks and then scrolls on the edit it will navigate a predefined list of strings. I want to capture the scroll event in order to update the edit text step by step.
This kind of behavior is implemented by the Spin Edit; I don't want to use the spin edit control since it only uses a list of integers and the spin buttons are too small.
Is there a way to catch the mouse scroll event for the CMFCRibbonEdit control? How to approach message handling for the ribbon (other messages than the COMMAND allowed by the ribbon designer). I'm using VS2010 on Windows 7 and the ribbon was designed with the ribbon designer?
View 4 Replies
View Related
Apr 24, 2013
I am certain that this is possible, but cannot figure out how to do it.
View 7 Replies
View Related
Nov 21, 2012
I am working on a project in which we capture a video using DirectShow samples. I want to know whether it is possible to capture a video with No noise, No interference etc. in other words, we want to capture High Quality (HD) video using DirectShow.
Is there any sample defined in DirectShow using which we can capture HD video.
View 4 Replies
View Related