Click here to Skip to main content
16,014,650 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Passing values of object. Getting garbage. Pin
macrophobia20-Feb-05 23:43
macrophobia20-Feb-05 23:43 
GeneralRe: Passing values of object. Getting garbage. Pin
David Nash21-Feb-05 3:10
David Nash21-Feb-05 3:10 
GeneralUPDATE - Passing values.Getting garbage. Pin
macrophobia21-Feb-05 2:01
macrophobia21-Feb-05 2:01 
GeneralRe: UPDATE - Passing values.Getting garbage. Pin
David Nash21-Feb-05 3:32
David Nash21-Feb-05 3:32 
GeneralRe: UPDATE - Passing values.Getting garbage. Pin
David Nash21-Feb-05 12:19
David Nash21-Feb-05 12:19 
GeneralRe: UPDATE - Passing values.Getting garbage. Pin
macrophobia21-Feb-05 15:44
macrophobia21-Feb-05 15:44 
GeneralRe: UPDATE - Passing values.Getting garbage. Pin
macrophobia21-Feb-05 16:25
macrophobia21-Feb-05 16:25 
GeneralRe: UPDATE - One final suggestion Pin
David Nash22-Feb-05 2:31
David Nash22-Feb-05 2:31 
Hi Travis,

I'm happy to help, and I'm glad your code is working now. Smile | :)
One final suggestion if I may.

Its a little unusual in C++ to create a class object and then set it's values. Normally you would use a constructor to either assign values when the object is created, or set values to a sensible default. That way, whenever the object is used, it's member variables are guaranteed to have assigned values, and the problem you experienced would never arise.

In your case, your code could look something like this.
//Bread.h
class Bread
{
public:

    Bread(double fat,double carb,int calor,double fiber,
      std::string filename);
    void setValues(double fat,double carb,int calor,double 
      fiber);

    std::string strFileName;
    double dblFat;
    double dblCarb;
    double dblFiber;
    int intCalor;
};


Bread.cpp might look something like this....
//snip

Bread::Bread(double fat,double carb,int calor,double
  fiber,std::string filename)
{
    dblFat = fat;
    dblCarb = carb;
    intCalor = calor;
    dblFiber = fiber;
    strFileName = filename;
}

//snip 

int main()
{
    Bread breadobject(1.1, 11.4, 60, 0.9, "White Slice");

//  breadobject.setValues( 1.1 , 11.4 , 60 , 0.9 );
//  breadobject.strFileName="White Slice";

    dataOut(breadobject.strFileName, breadobject.intCalor, 
      2.2, 0.0, breadobject.dblFat, breadobject.dblCarb,
      breadobject.dblFiber, 0.0, 0.0, 0.0, 0.0); 

    return 0;
}


Its your code of course, and this approach might not suite your purposes. Its all up to you.

Cheers
Dave
GeneralInsert a dialog in MDI!! Pin
20-Feb-05 18:12
suss20-Feb-05 18:12 
GeneralRe: Insert a dialog in MDI!! Pin
Aamir Butt20-Feb-05 22:06
Aamir Butt20-Feb-05 22:06 
GeneralRe: Insert a dialog in MDI!! Pin
Maximilien21-Feb-05 0:30
Maximilien21-Feb-05 0:30 
GeneralEnabling HotKeys in an MFC based application Pin
PrashantJ20-Feb-05 17:47
PrashantJ20-Feb-05 17:47 
GeneralRe: Enabling HotKeys in an MFC based application Pin
ThatsAlok20-Feb-05 19:10
ThatsAlok20-Feb-05 19:10 
GeneralRe: Enabling HotKeys in an MFC based application Pin
22491720-Feb-05 19:37
22491720-Feb-05 19:37 
GeneralA Simple Problem Pin
SeanSheehan20-Feb-05 17:46
SeanSheehan20-Feb-05 17:46 
GeneralRe: A Simple Problem Pin
22491720-Feb-05 18:32
22491720-Feb-05 18:32 
GeneralRe: A Simple Problem Pin
SeanSheehan20-Feb-05 20:26
SeanSheehan20-Feb-05 20:26 
GeneralRe: A Simple Problem Pin
Jetli Jerry20-Feb-05 20:59
Jetli Jerry20-Feb-05 20:59 
GeneralRe: A Simple Problem Pin
SeanSheehan20-Feb-05 21:08
SeanSheehan20-Feb-05 21:08 
GeneralRe: A Simple Problem Pin
22491720-Feb-05 21:05
22491720-Feb-05 21:05 
GeneralRe: A Simple Problem Pin
SeanSheehan20-Feb-05 21:23
SeanSheehan20-Feb-05 21:23 
GeneralRe: A Simple Problem Pin
22491720-Feb-05 21:41
22491720-Feb-05 21:41 
GeneralRe: A Simple Problem Pin
Jetli Jerry21-Feb-05 3:36
Jetli Jerry21-Feb-05 3:36 
GeneralRe: A Simple Problem Pin
22491721-Feb-05 4:55
22491721-Feb-05 4:55 
GeneralRe: A Simple Problem Pin
Wes Aday21-Feb-05 4:59
professionalWes Aday21-Feb-05 4:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.