在 C++11 中是否有关于以下内容的任何已定义行为?(即 a = 1、2 或未定义)
void somefunc(int a, int b) {
std::cout << a << b << std::endl;
}
int i = 0;
somefunc(++i, ++i)
或者我应该写:
int i = 0;
int a = ++i;
int b = ++i;
somefunc(a, b);
我问的原因是我正在解析一个文件的选项,在一种情况下我想创建一个键值对。并具有类似于以下的功能:
std::string create_key(std::string &source, size_t &size, int &index) {
std:: string key = "";
while(index < size) {
// parse the string to create the key
++index
}
return key;
}
// Value is an base class for a template class. Allowing me to store values
// of different data types inside a container.
Value* create_value(std::string &source, size_t &size, int &index) {
Value* value = nullptr;
while(index < size) {
// determine type and assign it to value
++index;
}
return value;
}
std::map<std::string, Value*> create_object(std::string &source, size_t &size, int &index) {
std::map<std::string, Value*> object;
while(index < size) {
// the line I think produces the same issue as my original example
object.insert(std::pair<std::string, Value*>(create_key(source, size, index), create_value(source, size, index)));
++index;
}
}