Re: question

From: SaltPeter (SaltPeter_at_Jupiter.sys)
Date: 05/14/04

  • Next message: velthuijsen: "returning variables: shouldn't most have const added?"
    Date: Fri, 14 May 2004 01:38:06 -0400
    
    

    >if i have a class with only a private member function say a long
    >so teh construction would be

    Post in plain text. I see an integer and not a function as a private member
    in class A. You've not included the most important part in your code (how
    are the class instances invoked).

    <snip>

    >in the construction of B
    >B:B(const A paramA)
    >{
    >s=paramA /// CAN I DO THIS ???????
    >}

    >well teh compiler does not like it
    >rror C2065: 's' : undeclared identifier why?

    nobody but you knows why... how was A and B's cstor invoked?

    Explain what you are trying to do, if you are simply trying to construct a
    compounded object via an initialization list, then state your intentions.

    Meanwhile, here is an example which includes 2 cstor options to construct an
    instance of B. Some will argue that what you seek is a simple copy
    constructor.

    #include <iostream>

    class A
    {
     int n;
    public:
     A(const int& arg): n(arg) { std::cout << "A: cstor invoked\n"; }
     virtual ~A() { }
     void display() { std::cout << "private member n = " << n << std::endl; }
    };

    class B
    {
     A a;
    public:
     B(const int& arg): a(arg) { std::cout << "B(const int&): cstor
    invoked\n"; }
     B(const A& arg): a(arg) { std::cout << "B(const A& ): cstor invoked\n"; }
     virtual ~B() { }
     void display() { a.display(); }
    };

    int main()
    {
     A a(9);
     a.display();

     B b(99);
     b.display();

     B bb(a);
     bb.display();

     std::cout << std::endl;

     return 0;
    }


  • Next message: velthuijsen: "returning variables: shouldn't most have const added?"

    Relevant Pages

    • Re: Newbie Question about multiple system calls within loops
      ... NULL is a macro, commonly defined either as 0, or just as plain ... of a variadic function, if the preprocessor expands NULL to plain 0, ... Things will go wrong in the common situation where int is 32 bits, ...
      (comp.lang.c)
    • Re: STL algorithms with vectors of c++ objects
      ... however you are asking equal_range to compare one of these to an int. ... If socket_node_live is a private member, which it probably ought to be, ... That ought to work assuming the rest of your code is OK. ... > what i'm trying to do is to get the pair of iterators ...
      (microsoft.public.vc.stl)
    • Re: Why would someone use c++ compiler on a C code?
      ... it's even pickier than its "plain C" counterpart. ... int main{ ... 'class' is not a valid identifier in C++ ... The character constant 'a' is of type int in C, ...
      (comp.lang.c)
    • Re: plain int and signed int
      ... Can signed int and plain int be different or are they guaranteed to be ... may not have the same representation. ... only two representations shared among the three distinct types ...
      (comp.lang.c)
    • Re: c++ code snippets site
      ... It's just plain wrong. ... 'std::string::size_type', not 'int'. ... Why use an array when you have the much safer and easier ... to use containers, e.g. vector? ...
      (comp.lang.cpp)