- 论坛徽章:
- 0
|
#include <string>
#include <iostream>
using namespace std;
main()
#if 0
{
//error note:
// non-aggregates cannot be initialized with initializer list
typedef struct test{
string a;
string b;
int c;
};
struct test *pins;
struct test ins1={"abc","def",3};
pins=&ins1;
pins->a="aaa";
pins->b="bbb";
}
#endif
#if 0
{
// success!
typedef struct test{
int a;
int b;
int c;
};
struct test *pins;
struct test ins1={1,2,3};
pins=&ins1;
pins->a=3;
pins->b=3;
}
#endif
上面的提示错误,下面的就成功了。
通过MSDN查看:
The specified identifier was incorrectly initialized.
An initializer list is needed to initialize the following types:
An array
A class, structure, or union that does not have constructors, private or protected members, base classes, or virtual functions
上面的带有string的结构不是aggregates吗? |
|