Re: question
From: SaltPeter (SaltPeter_at_Jupiter.sys)
Date: 05/14/04
- Previous message: Ulrich Eckhardt: "Re: question"
- In reply to: CTG: "question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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;
}
- Previous message: Ulrich Eckhardt: "Re: question"
- In reply to: CTG: "question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|