?
Solved

Class as an array???

Posted on 2003-02-22
4
Medium Priority
?
199 Views
Last Modified: 2010-04-01
I am trying to create a simple library.

class site{
 public:
  site();
  void ping();
 private:
  int interval;
  char domain[20];
};

I am going to use it to handle a bunch of domains and ping them at a given interval.  So if I wanted to handle 10 domains would I want:

site domain[10];

so then to ping one i could use

domain[0].ping;

Would that be correct?  Am I even doing this right?  Is there a better way to do it?  Sorry, I am kind of new to C++.
0
Comment
Question by:blaksaga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Exceter
ID: 8001906
0
 

Author Comment

by:blaksaga
ID: 8001909
Sorry about that...it was an accident
0
 

Accepted Solution

by:
Fallen_Knight earned 80 total points
ID: 8001911
that would be correct.

if you were dynamicly allocating then you would use:

site *domain;
domain = new site[10];

for(int i = 0; i < 10; i++) {
    domain[i].ping;
}

//free used memory
delete [] domain;
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8001926
>> domain[i].ping;

ping is a function! It needs to be called like this,

domain[i].ping();

Exceter
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question