Hello,

i was wondering how i can get my program to function... piecing it together bit by bit.

Problem i'm having right now... i'm trying to get my class to point to the array that i have built inside the main function:

char n=5;
		char rndseq[]={16,34,57,79,121};
		int ntimes=100000;
		Prob1Random a(n,rndseq);

here is the header:

// Specification file for the Prob1Random class
#ifndef PROB1RANDOM_H
#define PROB1RANDOM_H

class Prob1Random
{
	private:
		char *set;      //The set of numbers to draw random numbers from
		char  nset;     //The number of variables in the sequence
		int  *freq;     //Frequency of all the random numbers returned
		int   numRand;  //The total number of times the random number function is called
	public:
		Prob1Random(const char,const char *);     //Constructor
		~Prob1Random(void);                       //Destructor
		char randFromSet(void);                   //Returns a random number from the set
		int *getFreq(void) const;                 //Returns the frequency histogram
		char *getSet(void) const;                 //Returns the set used
		int getNumRand(void) const;               //Gets the number of times randFromSet has
		                                          //been called
};
#endif

here is the resource file:

#include <iostream>
#include <string>
#include "Prob1Random.h"		// Prob1Random class header
using namespace std;


// Definition of Prob1Random class constructor

Prob1Random::Prob1Random(const char n,const char* rndseq){
	nset = n;		//Assign number of values to pull random function from
	set = rndseq;	//Set pointer to random sequence
}

i'm simply trying to get the set pointer inside the class to point to the rndseq array inside my main function. any assistance would be great! thanks.

Recommended Answers

All 6 Replies

>any assistance would be great!
You neglected to mention what problem you're having.

>i'm trying to get my class to point to the array that i have built inside the main function:
That's a very bad idea. When classes don't have control over the memory for their members (either directly or indirectly), it gets hairy quickly.

>any assistance would be great!
You neglected to mention what problem you're having.

>i'm trying to get my class to point to the array that i have built inside the main function:
That's a very bad idea. When classes don't have control over the memory for their members (either directly or indirectly), it gets hairy quickly.

the problem i'm having is fixing this point in my code to get the class to point to the array in my main function:

set = rndseq;	//Set pointer to random sequence

i understand its a bad idea, but its how the problem requests completion.

>the problem i'm having is fixing this point in my code to
>get the class to point to the array in my main function:
That's not what I meant. I meant, what error are you getting when you try to compile? You can't just point out a line of code and expect someone to magically know what's wrong with it. While that's the case for some of us (you're trying to assign a const char* to a non-const char *) it's polite to provide as much information as possible for troubleshooting your problem.

p.s. Change char *set; to const char *set; .

oh i got you. sorry. here it is:

1>Linking...
1>homeworkmain.obj : error LNK2019: unresolved external symbol "public: __thiscall Prob1Random::~Prob1Random(void)" (??1Prob1Random@@QAE@XZ) referenced in function "void __cdecl problem1(void)" (?problem1@@YAXXZ)
1>F:\Documents\Debug\homework.exe : fatal error LNK1120: 1 unresolved externals


that is after i changed it to const char. getting 2019. i dont know how to troubleshoot errors like that.

>i dont know how to troubleshoot errors like that.
Unresolved externals means that you muxed up the definition of a function. In this case you haven't defined all of the member functions in the class.

After thinking about this i realized that i should not have asked questions about this on the forum, as the final does presumedly have a "no help" policy. please refrain from any further followup. I requested removal of this thread but i was denied by a moderator, so if i could at least get it locked it would be appreciated.

thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.