KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to create multiple objects using a for loop, as eventually I will want this program to create different numbers of the class depending on my input. I tried to write this using an answer to a previous question . However, when I try to compile I get the error 'no matching function for call to 'Genes::Genes()' #include <iostream> #include <cstdlib> #include <ctime> using namespace std; float random(); class Genes{ public: double cis; double coding; double effect; Genes(double a, double b, double c); }; Genes::Genes(double a, double b, double c) { cis=a; coding=b; effect=c; }; int main() { int geneno, i; srand(time(NULL)); geneno=4; //this will probably be cin later Genes *genes=new Genes[10] for(i=0;i<=geneno;i++){ double d,e,f; d=random(); e=random(); f=random(); genes[i]=Genes(d,e,f); cout<<"cis is "<<genes.cis<<'\n'; cout<<"coding is "<<genes.coding<<'\n'; cout<<"Effect for gene is "<<genes.effect<<'\n'; } delete[] genes; } float random(){ float decRANDMAX; decRANDMAX=RAND_MAX*1.0; return rand()%(RAND_MAX+1)/decRANDMAX; }
Tags (comma-separated)
Save Edits
Cancel