Structure initialisation

R

Raghu

Hello all,

I have a problem in intialising a structure which contains an objetc ofa a
class.I am getting the compiler error C2440.

For example.

struct test
{
MyClass t1_f;
UWORD t2_uw;

};

And if i intialise the structure as follows:

struct test myTest_st[2] = {
{
0.0f,
20
},
{
1.0f,
20
}
};

I am getting the compiler error as follows:
error C2440: 'initializing' : cannot convert from 'const float' to 'struct
test'
No constructor could take the source type, or constructor overload
resolution was ambiguous.

Please help me to resolve it.


Thanks in advance

Raghu.
 
I

Ian Collins

Raghu said:
Hello all,

I have a problem in intialising a structure which contains an objetc ofa a
class.I am getting the compiler error C2440.

For example.

struct test
{
MyClass t1_f;

What's MyClass?
 
R

Raghu

Hello Ian Collins,

Here is Myclass.

class MyCalss
{
public:
MyClass(float InitValue = 0.0f):Data(InitValue)
{
}
// Destructors
~MyClass();
//Copy Constructor
MyClass(const MyClass&);

float Data;

};

thanks in anticipation.

Raghu
 
I

Ian Collins

Raghu said:
Hello Ian Collins,

Here is Myclass.

class MyCalss
{
public:
MyClass(float InitValue = 0.0f):Data(InitValue)
{
}
// Destructors
~MyClass();
//Copy Constructor
MyClass(const MyClass&);

float Data;

};
Please don't top post.

You can't statically initialise an object with member function or
constructors. Only plain structs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top