C/C++ :: Difference Between Auto And Decltype In 0x
Jun 7, 2012
I'm having trouble with auto and decltype.
void f(const vector<int>& a, vector<float>& b) {
typedef decltype(a[0]*b[0]) Tmp;
for (int i=0; i < b.size(); ++i) {
auto p0 = new auto(a[i]*b[i]);
auto p1 = new decltype(a[i]*b[i]);
[Code] ....
The above code runs well in GCC4.7.
Could I use 'new auto(a[0]*b[0])' to allocate memory for the type of a[0]*b[0]?
And I can not distinguish the difference between decltype and auto in this case.
There are two types of patients. which is: 1. Normal patient. 2. Critically ill patient.
once you added any patient. You will be able to show all patient using "ShowAllPatient;" method. -> i want the Auto-increment ID Number to appear for each patient has been added.
And you will be able to call a patient to provide a hospital services for him/her using "GetNextPatient;" method.
I need to generate an Auto-increment Number for each (patient) has been added. (Auto-increment Number) but it just should be different for each patient. For example the first patient will have 1, The second patient will have 2. etc. The Auto-increment number should appear for each patient.
public class MyClass { public int age { get; set; } } static void Main(string[] args) { MyClass testing = new MyClass(); testing.age = 44; Console.WriteLine(testing.age); }
output: 44
Code using regular variable declaration:
public class MyClass { public int age; } static void Main(string[] args) { MyClass testing = new MyClass(); testing.age = 44; Console.WriteLine(testing.age); }
output: 44
Why use the auto-implemented property when you can just as equally use the second code block to achieve the same thing?
Okay so what I want to do is :- Create a program that can, say for example, switch to an already opened up google search page. Type in a given string and press enter.
Once more. The google search page is open.[Type anything on google.com and then THAT next page is the one ..] **So , the search box ,where you enter text has fixed coordinates.. (Which website doesnt matter, only coordinates do!)
I want the mouse to go to those coordinates, *click* and now a cursor will appear on the search box.
After this I want to send a fixed string output...That is , it should actually type in the string in that search box. then press enter.
That's it . [P.S. - obviously I don't want to do this with google, that was just an example.]
Mini Algorithm-
1)Get the mouse pointer to the x-y coords 2)Click! 3)Type in the fixed string. 4)Enter..
I can put it in a loop, don't bother with the easy bits I need to know how to control the mouse, and how to send the input string. Code snippets would be perfect
Create a program that can, say for example, switch to an already opened up google search page. Type in a given string and press enter.
Once more. The google search page is open.[Type anything on google.com and then THAT next page is the one ..] **So , the search box ,where you enter text has fixed coordinates. (Which website doesnt matter, only coordinates do!)
I want the mouse to go to those coordinates, *click* and now a cursor will appear on the search box. After this I want to send a fixed string output...That is , it should actually type in the string in that search box. then press enter.
Mini Algorithm- 1)Get the mouse pointer to the x-y coords 2)Click! 3)Type in the fixed string. 4)Enter..
I can put it in a loop, don't bother with the easy bits I need to know how to control the mouse, and how to send the input string. Code snippets would be perfect .
Right now I am trying to make an alarm clock type program that will start on login and will go off when a certain time is reached. I also want to set a password that will prevent system use until the correct password is entered into the program's input. What functions will I need and how are they used?
I'm trying to code a program in Dev-C++ for auto complete text in a web form. I'm using windows.h and mouse_event() function for move cursor position and click buttons, but I need write in a inputs/textarea a text.
Background: I'm making a small game using CodeBlocks and SDL. All of the code resides in a class named Game - the only thing running in Main is the creation of the Game object and the class function execute(). So far, I've made a Start Menu with three clickable buttons. I'm in the midst of making one of the buttons - Load Game - change the game screen to the Load Game menu. Basically, when the user clicks the button, the image on screen changes according to the button they click.
Issue: After successfully making the Load Game button change the image on the screen, I found that the SDL window mysteriously closes out several seconds after the image change. What is causing this - the window stays on perfectly fine until the background image is changed and the only way to break the loop is for the player to click the x on the window. I've gone over the code several times and haven't found anything that might be the cause.
Output: - Window with an Start Menu image and a button with the words "Load Game". - If user clicks the X on the window, the window closes. - If user clicks "Load Game" button, Start Menu image changes to Load Game image. After about seven seconds, the window automatically closes out. This isn't supposed to happen.
I created a table called registration and I have set an auto increment ID for each record. The problem is when I delete a certain record the ID didn't remove or deleted, for example if I entered these records: -
1,Bob,Bob123,Bob_2@hotmail.com then if I deleted it the next id record will be 2 which is supposed to be 1.
here is the SQL Command:-
CREATE TABLE Registration ( Reg_Id INT PRIMARY KEY IDENTITY, Name varchar (255), UserName varchar(255) NOT NULL, Reg_Password varchar(255), Email varchar(255), Reg_Rank varchar(255) );
I thought I'd display my fun use of the new C++11 auto keyword to create a compile time foreach. It only works for STL collections, or anything that implements the STL collection iterator methods begin(), end() that return a STL iterator.
// Standard Template Library foreach // element = iterator name // collection = STL data collection variable #define stl_foreach(element, collection) for(auto element = collection.begin(), __end__ = collection.end(); element != __end__; element++) }
Apparently the default behavior with Direct2D when rendering is to scale everything I render based on the size of the render target/window. How can I prevent this? I want to decide for myself when to scale the image, regardless of the size of the window.
Code: fn(){ char c; if (runFirstTime){ #ifdef VC c=''; #else c='/'; #endif } ... // c is used in the rest of the function to construct some pathnames }
The problem is that the value of c is not defined the 2nd time the function is called (and subsequently). It somehow worked fine under CygWin compiled with gcc. So I didn't spot the flaw until it ran incorrectly under Windows complied with VC++ 2010. Then I found the error and changed the code to something like
So now it works correctly under Windows. Then I re-compiled the new code with gcc and to my surprise gcc produced exactly the same binary! How can this be? Does the gcc compiler see my flaw and fix it for me somehow?
I am trying out a technique for a singleton class:
// access controlled singleton, accessed through function "instance()" // singleton is constructed in this function // so that constructor and destructor will be used class single { // private constructor/destructor
[Code] .....
Playing around with the code in main(), I am having trouble with auto:
single& s = single::instance(); // works fine auto a = single::instance(); // error ~single() is private
When I make the destructor public, the output of the program is:
ctor dtor dtor
So I fixed this by typing auto&. I'm still confused though, why wouldn't auto know I am returning a reference?
I am trying to create a flexible interface for my CL application. And what i have is this :
Code: using namespace std; // iplcp -i queryFile -d databaseFile template <typename INT, typename CHARA> class API {
vector<string> files; vector<INT> flags;
[Code] ....
and in main :
int main(int argc, char **argv){ //set variables API<int, char**>args(argc,argv); cout << "In file: "<< args.GetOpt("i") << " Db file: " << args.GetOpt("h") << endl; }
// first thing to be printed should be string and the second int
I know this is not probably the best way to but i am laying around and was curious if something like this could work . Are there any good C++ templates for CLI applications from which i could learn?
I am developing a program that needs auto start at windows startup. For that I need to add Registry entries. Also the program needs to read some registry keys. What are the functions i need to do these.. Simply I need to
check if the startup key already exists add a new key if it doesn't exist read a key values
I am writing a program to auto login in a web site. Before making next attempt I have to wait for some time like some 10 seconds(it is configurable). But during waiting UI should not freeze. I wrote code something like this. Here event m_hEvent[1]) will be set by another thread after 10 seconds.The problem is UI still freezes some times!
while(1) { //m_hEvent[1] will be set by another thread after 10 seconds dwRet = MsgWaitForMultipleObjects(1, &m_hEvent[1], FALSE, dwMilliseconds, QS_ALLINPUT); ResetEvent(m_hEvent[1]);