Passing values to a class

D

Donos

Hello

I have a program as given in following,

class CCmdValue
{
int a, b;
void Put(int x, int y) { a = x; c = y;}
};

class CCmdData
{
CCmdValue pValue;
pValue->Put(10, 20);

CCmdModule pCmd;
pCmd.NewValues(pValue);
};

class CCmdModule
{
friend class CCmdModuleFactory;
CCmdValue mValue;
};

class CCmdModuleFactory
{
CCmdModule& NewValues(CCmdValue& pValue)
{
CCmdModule* p = new CCmdModule;
p->mValue = pValue; // THIS LINE FAILS
}
};

When i try to pass the value of "pValue" to "mValue" It fails. It
doesn't give any compilation error, but when i try to read the integer
values, they don't have any vlaues assigned to them.

Any idea why thats happening?

Thanks in advance.
 
R

red floyd

Donos said:
Hello

I have a program as given in following,

class CCmdValue
{
int a, b;
void Put(int x, int y) { a = x; c = y;}
};

This class has no public methods, so you can't really do anything with
it other than default construct, copy construct, or assign it.
class CCmdData
{
CCmdValue pValue;
pValue->Put(10, 20);
This should give a compile-time error.
CCmdModule pCmd;
pCmd.NewValues(pValue);
};

class CCmdModule
{
friend class CCmdModuleFactory;
CCmdValue mValue;
};

class CCmdModuleFactory
{
CCmdModule& NewValues(CCmdValue& pValue)
{
CCmdModule* p = new CCmdModule;
p->mValue = pValue; // THIS LINE FAILS
}
};

When i try to pass the value of "pValue" to "mValue" It fails. It
doesn't give any compilation error, but when i try to read the integer
values, they don't have any vlaues assigned to them.

Any idea why thats happening?

How about providing a minimal, compilable, executable sample that
exhibits the behavior in question?
 
J

Jim Langston

Donos said:
Hello

I have a program as given in following,

class CCmdValue
{
int a, b;
void Put(int x, int y) { a = x; c = y;}
};

class CCmdData
{
CCmdValue pValue;
pValue->Put(10, 20);

CCmdModule pCmd;
pCmd.NewValues(pValue);
};

class CCmdModule
{
friend class CCmdModuleFactory;
CCmdValue mValue;
};

class CCmdModuleFactory
{
CCmdModule& NewValues(CCmdValue& pValue)
{
CCmdModule* p = new CCmdModule;
p->mValue = pValue; // THIS LINE FAILS
}
};

When i try to pass the value of "pValue" to "mValue" It fails. It
doesn't give any compilation error, but when i try to read the integer
values, they don't have any vlaues assigned to them.

Any idea why thats happening?

Doing almost anything with these classes as they are shown here will give
compile time errors, since nothing is declared public. Everything is
private to each of the classes. Also, there are syntax errors. CCmdValue
pValue; is an instance. Yet you use it as a pointer, which would produce an
error.

Please show the actual code that is causing the problem.
 

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
474,200
Messages
2,571,046
Members
47,646
Latest member
xayaci5906

Latest Threads

Top