How to instantiate an object within another object

I am trying to wrap a NTP time client in an object/library so I can reuse it. If I pass the time server in the constructor and instantiate the Ethernet client (in the constructor) I cannot use it within the whole class. I get a compile error referencing scope.

I don't want to pass the client as a variable either since I want the NTP object to do everything.

Could someone help me determine how to get around this issue?

Hi, here is a long thread about the same topic with a solution (sort of)

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260904176 Eberhard

I fixed it by instantiating the Ethernet object as a variable of the time client object. But when doing so you can't pass it variables (otherwise it would need to be in the constructor).

I hacked the Ethernet class and added a blank constructor and a method to set the IP and port later.

This allowed me to instantiate Ethernet class within the time client class, then set the ip and port and finally connect.

All this for cleaner code!!!