• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Class as an array???

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
blaksaga
Asked:
blaksaga
  • 2
1 Solution
 
ExceterCommented:
0
 
blaksagaAuthor Commented:
Sorry about that...it was an accident
0
 
Fallen_KnightCommented:
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
 
ExceterCommented:
>> domain[i].ping;

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

domain[i].ping();

Exceter
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now