declaration

Why gcc is complaing about gets()

不想你离开。 提交于 2019-12-24 00:23:33
问题 This is my code(simplified): #include <stdio.h> #include <string.h> #define SIZE 240 int main(void) { char word[SIZE]; gets(word); return 0; } Why GCC is giving me №3.c: In function ‘main’: №3.c:13:2: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration] this warning? GCC vesion is 5.2.1 P.S.The program is working. P.P.S. I will never use gets(), I will never use gets(), I will never use gets(), I will never use gets() 回答1: Function gets is not supported by the C

Multidimensional array initialization seems sensitive to whitespace

ぐ巨炮叔叔 提交于 2019-12-23 15:39:55
问题 I noticed a difference between those two declarations where only the position of the comma changes: $a = @( @('a','b'), @('c','d')) $b = @( @('a','b') , @('c','d')) In this case, $a.length evaluates to 2 and $b.length evaluates to 3. The first sub-array of $b has been flattened. Is this a feature and where can I find its documentation? By the way, $PSVersionTable : Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.42000 BuildVersion 6

C++ method declaration question

半城伤御伤魂 提交于 2019-12-23 12:01:05
问题 I have some code in Image.cpp: Image::Image( int width, int height, int depth ) : m_sFileName(0) { ... } and in Image.h: class Image: public DrawAble, public RenderAble { ... private : std::string *m_sFileName; }; My question is: what is happening with m_sFilename in the first line? I guess it is set to NULL but what's the point of doing it that way. Would it be the same to do: Image::Image( int width, int height, int depth ) { m_sFileName(0); ... } 回答1: The first uses what's called an

Conditional variable declaration

こ雲淡風輕ζ 提交于 2019-12-23 09:52:02
问题 I'm coming from Python and I have some problem with managing types in c++. In Python I can do something like this: if condition_is_true: x=A() else: x=B() and in the rest of the program I can use x without caring about the type of x, given that I use methods and member variables with the same name and arguments (not necessary that A and B have the same base classes). Now in my C++ code type A corresponds to typedef map<long, C1> TP1; and B to: typedef map<long, C2> TP2; where: typedef struct

Efficiency of C Variable Declaration [duplicate]

耗尽温柔 提交于 2019-12-23 08:50:41
问题 This question already has answers here : How is conditional initialization handled and is it a good practice? (5 answers) Closed 5 years ago . How long does it take to declare a variable in C, for example int x or unsigned long long var ? I am wondering if it would make my code any faster in something like this. for (conditions) { int var = 0; // code } Would it be faster to do this, or is it easier not to? int var; for (conditions) { var = 0; // code } Thanks for the help. 回答1: Whenever you

Why does this separate definition cause an error?

烈酒焚心 提交于 2019-12-23 07:56:10
问题 Challenge: I have this code that fails to compile. Can you figure out what's wrong? It caused headache to me once. // header namespace values { extern std::string address; extern int port; } // .cpp file std::string ::values::address = "192.0.0.1"; int ::values::port = 12; It looks correct on the first sight. How many and which are the errors!? 回答1: One error: std::string values::address = "192.0.0.1"; is the proper form, otherwise the parse is std::string::values::address = "192.0.0.1"; and

'SHGFP_TYPE_CURRENT' was not declared in this scope

允我心安 提交于 2019-12-23 05:19:06
问题 I am migrating a huge project from Qt 4.x to 5, (in fact I have asked for help several times here, I couldnt be more grateful for your help). I am getting the next error: ..\marssies\userlayerswidget.cpp: In member function 'void LayersModel::importFromOld()': ..\marssies\userlayerswidget.cpp:1736:60: error: 'SHGFP_TYPE_CURRENT' was not declared in this scope It doesnt make too much sense, as I have the correct header included, here are all the includes: #include "userlayerswidget.h" #include

'Do something' if key exists in hash1 and not in hash2

别来无恙 提交于 2019-12-23 04:55:19
问题 I've written some code that finds overlapping keys in 3 different HoAs that contain some information on which I sort them later: #!/usr/bin/perl use warnings; use strict; my @intersect; for my $key (sort keys %hash1) { if (exists $hash2{$key} && $hash3{$key} ) { my ($hit1, $percent_id1) = @{ $hash1{$key}[-1] }; my ($hit2, $percent_id2) = @{ $hash2{$key}[-1] }; my ($hit3, $percent_id3) = @{ $hash3{$key}[-1] }; push @intersect, "$key\tC1:[$condition1]$hit1 [$percent_id1]\tC2:[$condition2]$hit2

default argument promotions in the case of inplicit function declarations

穿精又带淫゛_ 提交于 2019-12-23 04:22:50
问题 I've tried to search in old questions but I've not solved my problem. I try to explain my doubt; Supposing to work in c89 mode, if there's not a prototype of the function before the function call, there is an implicit declaration of the function, the type of the function is int and the arguments are converted through Default Argument Promotions: the objects of type char or short int (whether signed or not) are promoted to either int or unsigned int, as appropriate; and that objects of type

C++/CLI : How to declare template array as method parameters

。_饼干妹妹 提交于 2019-12-23 03:12:48
问题 I am a newbie to C++/CLI. What is the equivalent of the following C# code in managed C++/CLI for both the header and source file? public static bool ArrayEquals<T>(T[] a, T[] b) { return true; } 回答1: Here is the content for the source file: public: generic <typename T> static bool ArrayEquals(array<T>^ a, array<T>^ b) { return true; } 回答2: I tried the following and kept getting linker errors. Now I know, the keyword generic should be used instead. Thanks Laurent! :) template<typename T> bool