declaration

Character variable with dynamic length

岁酱吖の 提交于 2019-12-13 10:17:07
问题 Is there any way to declare char variable (or maybe string) with the length which is calculated dynamically? This coding clarifies what I want: DATA: len TYPE i, a TYPE i, b TYPE i. len = a + b. DATA: var(len) TYPE с. Do not propose solutions with CREATE DATA and/or field symbols: I've tried them but they are not applicable in my case. The intention of such declaration is adding leading zeroes and/or apply other logic to this string. Therefore string is to be declared strictly ! Any proposals

Templated Proxy design pattern

♀尐吖头ヾ 提交于 2019-12-13 09:02:59
问题 I have a simple and reproducible code, which looks like so: template <typename T> class Proxy { private: Wrap<T> &self; // If I comment this, it will work public: Proxy() {} }; template <typename T> class Wrap { T *p; public: Proxy<T> foo() { return Proxy<T>(); } }; int main() { return 0; } The error I get is: 'Wrap' does not name a type If I comment Wrap<T> &self , then it will work, but this is not what I need. I need Wrap<T> to be a member of Proxy class. How can I achieve this? 回答1: You

putting a '&' after the type [duplicate]

為{幸葍}努か 提交于 2019-12-13 08:57:35
问题 This question already has answers here : ampersand (&) at the end of variable etc (5 answers) Closed 5 months ago . I am fairly new to programming. I am just moving on to C++ from C in my college courses, and I encountered something that I haven't seen before in C. Sometimes after the type, either in a function declaration or passing a parameter, a & immediately follows the type. For example, we use a struct called Customer in one of our projects, and some of the functions pass Customer& .

Creating dynamic declaration of array

你离开我真会死。 提交于 2019-12-13 08:36:36
问题 I want make array wich will be declared dynamically I imagine somethnig like this.I want make program that recognize characters in the word. char i; scanf("%c",&i); char word[]=i; printf("%c",word[0]); i also tried something like this char i; scanf(%c,&i); char *word=i; printf("%c",word[0]); i have no clue how to make it work 回答1: Let's just start with the basics. What you are declaring when your write: char word[]=i; is an array of characters which will be initialized based on what is to the

Declare value in c++ header

无人久伴 提交于 2019-12-13 07:15:40
问题 Well, i'm a newbie to C++ from Python and not familiar with declaring variable in header file. I am trying to create several .cpp file in which calculate some values from some the same constant value set. My code something like: /Global_input.h/ extern int y = 1; extern int x = 2; /Properties_1.cpp/ //I wanna calculate z = x + y include<Global_input.h> int z; /Properties_2.cpp/ //I wanna calculate g = x*y include<Global_input.h> int g; I got stuck here, the way I search is create a new class

dynamic variable declaration

喜你入骨 提交于 2019-12-13 06:20:42
问题 Suppose we have loaded data into cell array: DATA={'foo',[1,5];'bar',[2,6]} Is there way how to declare variables named by 1st column in DATA with content of 2nd column? 回答1: You can do that using eval for ii = 1:size(DATA,1) eval( [DATA{ii,1}, ' = ', num2str( DATA{ii,2} )] ); end However, use of eval is not recommended. You can use dynamic field names instead: s = cell2struct( DATA(:,2), DATA(:,1), 2 ); 回答2: There's an assignin function which takes a variable name and assign to it a specific

How do i declare and define a variable of a custom type in one line

眉间皱痕 提交于 2019-12-13 05:14:32
问题 How can i declare and set a custom type in one line. Option Explicit Type Stackoverflow stack As String overflow As String End Type Sub WorkingExample() Dim example As Stackoverflow example.stack = "stack" example.overflow = "overflow" MsgBox (example.stack + example.overflow) End Sub Sub NotCompiling() Dim example As Stackoverflow = {.stack = "stack", .overflow = "overflow"} MsgBox (example.stack + example.overflow) End Sub In this mini example the WorkingExample shows the behavior i want

C++ vector: declaring multiple variables with names xxx1, xxx2…xxxN (N loaded from file)

大城市里の小女人 提交于 2019-12-13 04:14:00
问题 I am up to upgrade a program to make it dynamically configurable from files. What i need is a number of vector viables, and that number being dependant of int variable. int k=4 //loaded from file, i handled it vector<string> NAME(k) Moreover, names of those variables need to be rising numbers (first object: NAME1, second NAME2 etc.). This is my first ever post there, so sorry for all the mistakes or lack of information :) 回答1: You can't dynamically name variables, but you could store them in

Difference between vector<string> x; and vector<string> x(const string& s) {}

坚强是说给别人听的谎言 提交于 2019-12-13 03:18:11
问题 I'm learning about vectors in Accelerated C++ by Andrew Koenig and Barbara Moo. Can anyone explain the difference between these? vector<string> x; and vector<string> x(const string& s) { ... } Does the second one define a function x whose return type must be a vector and whose return value is stored somehow in x? The exact code from the book starts like this: map<string, vector<int> > xref(istream& in, vector<string> find_words(const string&) = split) { 回答1: vector<string> x; This is a

Declare variables names using string value data in cpp/c++

左心房为你撑大大i 提交于 2019-12-13 02:57:46
问题 for example lets say your pulling data from somewhere and you put it in a string variable then you want to use the data inside of it to be the another strings name: int main(void){ string strVar ="StringData"; //this is a string variable with text inside cout<<strVar<<endl; //displaying the variables contents string strVar.c_str() = "stuff in string variable 'StringData'"; //this uses what was inside of strVar to be the name of the new string variable cout<<StringData<<endl; //prints the