(this code does not work) Also I cannot to join it to one line because I don't use C++11.
And the second array which I need is to create array of times int and double
something like
1 2 3 4
constchar* predefinedArgTypes;
// implementation:
this->predefinedArgTypes[] = { int, int, int, int, double, double, int,
int, int, int, int, std::string }; // the last one is just example for string
Sounds like you want a dynamic array in the first instance. I'd suggest using the standard library vector and string types.
Unfortunately, if you're pre-C++11 then you don't have initialiser list support, so you'd not be able to do it in a one-er. You can create a vector with an initial set of values from an array pretty easily, though:
However it is not possible to declare zero size array like this
header:
1 2 3
std::string predefinedArgs[]; // cannot declare
nor this
std::string stringsAsArray[] = { "Some", "Other", "Strings" }; // this one is declaration + initiation
1 2 3
// header
I can dothis:
std::string predefinedArgs[12]; // declare
Edit: At this point I also feel obligated to share my feelings on how terrible I think the VS compiler is (very) and how much better life is when you migrate to a competent one (clang).
error: : 'Wrapper::{ctor}' : constructors not allowed a return type
based on that and some other hints (like the claim that "std::string stringsAsArray[] = { "Some", "Other", "Strings" };" does not compile), I am guessing that you need help writing a constructor that initializes a class member of type std::vector<std::string>.. but none of the code shown even shows a class, a constructor, or a member.
#include <string>
#include <iostream>
// Header file.
class Test
{
public:
staticconst std::string Args[] ;
};
// In your implementation file in the global scope.
const std::string Test::Args[] = {"string", "test"} ;
int main()
{
Test my_test;
for(int i = 0; i < 2; ++i)
std::cout << Test::Args[i] << ", ";
std::cout << std::endl;
}
Of course you'll need to include the proper header files in the appropriate files.
Yes I use classes, however I'm not stuck in the past using C++98. I suggest you update your compiler and start using the current standards. Also you didn't really post enough code to decipher that you were using a class.
By the way the code I provided compiles with a C98 compiler.
I'm not sure what more you want here. There have been solutions to your problem all through this thread.
Cubbi has given a perfectly succinct solution using vectors and a tidy way of initialising in your constructor. Not sure why you're not taking that.
If you're absolutely desperate to avoid vectors, I gave a solution in the fourth post that details how to do something similar with string arrays.
You seem to want a stack created array of strings that you can declare in one place, and implement in another in a one-liner. You can't. If you want this you need to heap allocate like I gave you in the example in the fourth post. If you want to stack create then you'll need to assign the string at each index individually - you cannot use an initialiser list.
My advice, aside from having a slightly better attitude towards those helping you, would be to take the eight lines of code offered by Cubbi at the end of his post that adequately solves your problem.