473,378 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Structure initialisation

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.

May 16 '06 #1
3 2478
Raghu wrote:
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?

--
Ian Collins.
May 16 '06 #2

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

"Ian Collins" <ia******@hotmail.com> wrote in message
news:4c*************@individual.net...
Raghu wrote:
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?

--
Ian Collins.

May 16 '06 #3
Raghu wrote:
"Ian Collins" <ia******@hotmail.com> wrote in message
news:4c*************@individual.net...
Raghu wrote:
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?

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.

--
Ian Collins.
May 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tim | last post by:
Please advise if you can. Presumably initialisation of members in member initialisation lists is perfomed by 'C' run-time startup. If the CRT was never started-up would those members be garbage?...
2
by: rashmi | last post by:
Hi All, ************************************************* error: variable `hdlc_cdevsw' has initializer but incomplete type *************************************************** This is the error...
2
by: Charles Law | last post by:
Does anyone know if it is possible to initialise a structure array at run-time, something like this: <code> Structure struct Dim a As String Dim b As Integer Dim c As End Structure
7
by: Jake Thompson | last post by:
Hello I created a DLL that has a function that is called from my main c program. In my exe I first get a a pointer to the address of the function by using GetProcAddress and on the dll side I...
13
by: Frederick Gotham | last post by:
I have just been reading 8.5 in the Standard, and am trying to make sense of the different kinds of initialisations. Up until now, I thought of an object as either NOT being initialised (i.e....
5
by: kselvaakumar | last post by:
I have declared a global structure like this: struct { float a; float b; }static one; This is in a separate header file file1.h; Now how can i initialise those variables one.a and one.b in...
8
by: Vj | last post by:
Hi all, I'm finding some people in my company defining a version number as a field to some structure. The sample code goes as follows: typedef enum _params_ver_ { UNDEF = 0, VERSION_1,
4
by: Kevin Frey | last post by:
I have an assembly written in C++/CLI that also links in non-clr Native C++ (the C++/CLI wraps the Native C++ functionality). This assembly has an in-built tracing system that needs to be...
3
by: cman | last post by:
I do not understand the use of a period to define structure members, one sees this frequently in kernel code. Please explain. Here is the structure: static struct file_system_type ext2_fs_type =...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.