C++ :: Passing Array Of Object Gives Compilation ERROR
Dec 21, 2012
This is my question : Define a class named HOUSING in C++ with the following descriptions:
Private members
REG_NO integer(Ranges 10 - 1000)
NAME Array of characters(String)
TYPE Character
COST Float
Public Members
-Function Read_Data( ) to read an object of HOUSING type
-Function Display() to display the details of an object
-Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING Use random function to generate the registration nos. to match with REGNO from the array.
Now I' trying to do this by this way
Code:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class housing {
private:
int REG_NO;
char NAME[10];
[Code] .....
I am trying to pass the entire array of object in DrawNos(). but getting compilation error -
32: 'housing:rawNos(housing * *)' is not a member of 'housing'
48: Structure required on left side of . or .*
What is the problem? How can I pass the array of object in function and use it.
View 3 Replies
ADVERTISEMENT
Oct 17, 2013
main:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Board.cpp"
int main(int argc, char* argv[]){
argc=5;
argv[argc];
[Code] .....
I can't find a place where there are two definitions of any of the Board methods
View 9 Replies
View Related
Nov 23, 2013
Code:
#include <Data.h>
int main(int arg_count, char** argv) {
if(arg_count!=3){
cerr<<"Files misisng
";
exit(1);
[code]...
This actually should work, because it is passing address of polymorphisms object.I have tried changing prototype of test in Data.h, but failed.passing object address/pointers in C++.
View 5 Replies
View Related
Apr 17, 2014
I am writing a program for a poker game.. I created a class to get cards and create deck.. the problem I am having now is how to deal 5 cards to an array to ve evaluated later. I want to call the array player1[5]. I tried to use pointer but I get the following error
#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <algorithm>
using namespace std;
const char* FaceString[13] = {"Ace", "2", "3", "4",
"5", "6", "7", "8",
"9", "10", "Jack", "Queen", "King"};
[code]....
View 4 Replies
View Related
Feb 3, 2014
This problem just seems really strange to me because it is simple yet for some reason my class cannot pass into another class. The class PASS_OBJECT has a static array (even with 1 element this doesn't work) and when I try to pass this class (after it is initialized) I seem to lose the data inside the PASS_OBJECT. Not only that but even when I declared the class OBJECT with the type of PASS_OBJECT<int> I seem to lose the integer 99. Here's the code, note that if you comment out line 89, 92 and 93 you will notice that line 90 outputs In main 2: 99 just fine but it doesn't otherwise???
#include <iostream>
const int size = 1;
template <class T>
class PASS_OBJECT;
template <class S>
class OBJECT {
[Code] ....
View 2 Replies
View Related
Jul 5, 2014
Considering this small code:
Here a template array class is written and also a cat class. The cat class has "present" method.
the array is initialized with 20 cats. yet, trying to activate a cat methods makes a compilation error:
Code:
#include <iostream>
using namespace std;
template <class T>
class Array{
private:
[Code].....
how do we make it work? I'm sure there's a way I'm not aware of since if we can't - what is the point of templates?
View 6 Replies
View Related
Nov 23, 2014
I'm trying to pass an 2d array to a function, but i'm getting this error message:
Error: 'p' undeclared here (not in a function)
#include <stdio.h>
void regStock(int stock[][p], int a);
int main( ) {
int a, p;
scanf("%d", &a);
scanf("%d", &p);
[Code] .......
View 6 Replies
View Related
Jun 8, 2013
I've been trying to work fix this piece of code to put into a project but I could not get it to work. I keep getting this error C2664: 'SumOfNumbers' : cannot convert parameter 1 from 'int' to 'double []' . I've worked every thing piece by piece but when I try to pass the array to the function I get the error and don't know what it means. Does C++ not allow what I'm trying to do?
Code:
#include <iostream>
using namespace std;
void SumOfNumbers(double Nbr[], int size);
int main()
[Code] ....
View 7 Replies
View Related
Dec 9, 2013
I am trying to make quicksort and binary search and I get error when I am passing dynamic array to argument. It also says error during initialization of the dynamic array.
//.h file
#ifndef SortableArray_h
#define SortableArray_h
#include <iostream>
#include <string>
[Code] ....
View 2 Replies
View Related
Sep 23, 2013
i want to modify value of whole array by passing it to a function and make each value of array multiplied by 3 ,return the value to main and print it using pointer.
error : invalid Lvalue is the error
Code:
#include<stdio.h>
main()
{
int i,arr[10];
for (i=0;i<=9;i++)
{
printf("Enter value of arr[%d] : ",i);
scanf("%d",&arr[i]);
[Code] ....
View 1 Replies
View Related
Dec 4, 2013
I've been working on a little project and hit a snag. I'm using nodes for a queue and stack class that were created using an existing list node class. I create an object for a student class and I want to enqueue that object.
int main() {
Queue sLine;
Customer stu;
Queue<Student &>
cLine.enqueue(cust);
}
That's basically the coding of it in main. However when I follow the error which says uninitialized reference member ListNode<Student& info>::data;
#ifndef LISTND_H
#define LISTND_H
template< class T > class List;
template< class NODETYPE >
class ListNode {
friend class List< NODETYPE >;
[Code] .....
What I may have been doing wrong? Trying to work within certain contexts.
View 2 Replies
View Related
Feb 13, 2013
This is supposed to check for valid input
if(((c.integer < 0)&&(c.numerator < 0))||(c.denominator<=0)) {
c.integer = 0;
c.numerator = 0;
c.denominator = 0;
}
if((c.integer>0)&&(c.numerator<0))
[Code] ....
And it does just fine, until it's passed into a function, then it doesn't work:
void validInput(Mixed a) {
if(((a.integer < 0)&&(a.numerator < 0))||(a.denominator<=0)) {
a.integer = 0;
a.numerator = 0;
a.denominator = 0;
[Code] ....
It works, when the object is passed, except for two cases (one where the minus sign shifts) and whenever there is a zero or a negative integer in the denominator.
Also, I'm passing the function like validInput(c);
View 4 Replies
View Related
Mar 29, 2013
Code:
void lexer(ifstream& inputfile) {
string line;
getline(inputfile,line);
[Code] ......
I am trying to pass input file between two functions. The code compiles but immediately upon running the program, there is a "bad cast" run time error.
View 9 Replies
View Related
May 5, 2014
I need to create a function in my program to open an input file and another function to open an output file and I need to use the files in other functions so Im trying to pass the stream object by reference but then i need a condition that tells the compiler not to reopen the file because then it will delete everything and make me input the file names again. Heres the two functions.
void InputFileOpen(ifstream &inFile) {
string file_name;
if(!inFile.is_open()){
cout<< "Enter the input file name: ";
cin>> file_name;
inFile.open(file_name, ios::in);
[code]....
View 4 Replies
View Related
May 20, 2014
I have a Qt classes as follow:
Code:
class Vehicle {
public:
void AddData(QString str, Data* data) {
_myDataMap.insert(str,data);
} virtual void Init();
[code].....
My questions are:
After the main function called d1->Modify; the data stored in _myDataMap will get modified too.
What is the more appropriate way of passing the Data through AddData in such case?
If i do AddData(const Data & data), i will not be able to use inheritance of Data, i.e passing a subclass of Data to AddData.
View 3 Replies
View Related
Jul 6, 2013
I want my function to take 'fstream' object as an input, so the program looks like this:
Code:
#include <fstream>
using namespace std;
void test(fstream a){
a.open("test2.txt");
a << "123" << endl
[Code] ....
But I get error: 'std::ios_base::ios_base(const std::ios_base&)' is private|
View 3 Replies
View Related
Feb 29, 2012
I am having an issue with passing an ifstream object to functions. Here is the code:
Code:
#include <fstream>
using namespace std;
void otherfunction (ifstream *ifs) {
...does stuff, like ifs->open(), then reads from the file...
}
int main () {
ifstream ifs();
otherfunction(&ifs);
}
Here is the error message:
Code: error: cannot convert ‘std::ifstream (*)()’ to ‘std::ifstream*’ for argument ‘1’ to ‘void otherfunction(std::ifstream*)’
Why can't I do that? What does "ifstream (*)()" even mean? And I don't want to change the structure of the program. I have reasons for declaring the ifstream object in the main function (because there are actually two functions that need access to the ifstream object -- neither of which is working).
Also, if I change the main function to be this instead:
Code:
int main () {
ifstream ifs();
ifstream *ifsptr = &ifs; //EDIT 2: forgot the ampersand
otherfunction(ifsptr);
}
I get the same error as above. However, if I change the main function to this:
Code:
int main () {
ifstream *ifsptr = new ifstream();
otherfunction(ifsptr);
}
I get all kinds of crazy errors about "undefined symbols for architecture _____". Here is the actual error message from my program (parseArgs is the real name of otherfunction)
Code:
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cchumGBV.o
"std::ios_base::Init::~Init()", referenced from:
[Code] .....
View 12 Replies
View Related
May 1, 2013
I am trying to pass an object to an inherited clas by a constructor. I am having Cboard my board and i need to pass it to the object Cpawn.
Here under is my code:
main
Code:
#include<iostream>#include "Cboard.h"
#include "Cpawn.h"
#include "Cpiece.h"
void main(){
char location[50];
[Code] ....
View 3 Replies
View Related
Dec 17, 2014
Here is my issue: I am making a simple audioplayer in Xamarin.android but i want every time i change the track to make a crossfade effect. So im using 2 mediaplayers at the same time for the fade. The problem is that im defining one time the players and i pass the player as a parameter like this:
public MediaPlayer player = null;
public MediaPlayer player2 = null;
....
If i have to fadeout the player and start the next one im doing it like this:
if (player != null){
if (player.IsPlaying) {
cts = new CancellationTokenSource();
token = cts.Token;
FadeOut (player, 2000 ,token);
[Code] .....
So my problmem is that player and player2 remain always null. Why? i guess c# creates a copy of player and player2 and use this one. How i can pass a mediaplayer as parameter and always use only player and player2?
View 8 Replies
View Related
Apr 29, 2014
I'm working through the Let us C book. One exercise asks me to collect int and float , then pass them to a function that gets product of these and returns it to main. My code looks like this:
Code:
#include <stdio.h>#include <stdlib.h>
main()
{
int a;
float b, c;
[Code]...
So while compiling i get an error about conflicting types for product. I tried to google that error but couldn't understand what's the problem. My only clue is that i can't pass int and float to a function at the same time... Could that be it?
View 6 Replies
View Related
Aug 29, 2014
I was running some Monte carlo simulations and I was having some trouble passing my Normal-Random-Generating object as a parameter to the simulator.
I created a class called BoxMull which used the Box-Muller algo to generate Normal randoms and I based the Box-Muller algo on random numbers generated by the Mersenne-twister engine.
I am getting an error while compiling.
#include <iostream>
#include <random>
#include <cmath>
const double pi = 3.1428;
template<class rnd_gen>
class BoxMull
[Code] ....
View 6 Replies
View Related
Mar 4, 2014
Write a program that computes how many feet an object falls in 1 second, 2 seconds, etc., up to 12 seconds.
1.Have a procedure called FallingDistance which has one input parameter, seconds, and one output parameter, distance.
2. Compute the distance in feet an object falls using this formula: d = ½ gt2
(where g = 32.2)
3. The main program should call FallingDistance within a loop which passes the values 1 through 12 as arguments.
4. Print a table with seconds and falling distance in feet.
Sample Output (This program has no input)
Seconds Distance
================
1 16.1000
2 64.4000
3 144.9000
4 257.6000
5 402.5000
6 579.6000
7 788.9000
8 1030.4000
9 1304.1000
10 1610
11 1948.1000
12 2318.4000
In C++, the procedure is called a function. Instead of using an output parameter, your C++ function FallingDistance should return a result of type double. This is what I created:
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
const double g =32.2;
double fallingDistance(double);
[Code] ....
which gave me this error:
1>------ Build started: Project: Lab 6, Configuration: Debug Win32 ------
1> Source.cpp
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(27): error C2065: 'fallingdistance' : undeclared identifier
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(36): error C2065: 't' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
View 4 Replies
View Related
Nov 24, 2013
Code:
class Main{
class B b_obj;
C c_obj=b_obj.test("some",89); // I cannot get this done.!
}
Below are .h files:
class B{
public:
C* test(const char *, int); /// this doesn't work
constructor
//member variables
[Code] ....
However, map<string, vector<bol>> test(const char *, int); works.I know second thing will work, but how to take reference of class object?
I have include .h file in main, B and C, wherever it is required.
View 4 Replies
View Related
Feb 14, 2013
I am using visual studio 2012 and i pass three command line arguments as 10 20 30 and when i m compile the program get error.....
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main(int n,char **p) {
int sum=0,i;
if(n>=2)
[Code] .....
View 2 Replies
View Related
Dec 15, 2012
I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure.
Code:
srand(static_cast<unsigned int>(time(0)));
int choice = rand() % NUM_WORDS;
string theWord = WORDS[choice][WORD];
string theHint = WORDS[choice][HINT];
[Code] ....
The error is happening on the last output operator, just before the jumble variable on the last line.The error is:
Code:
Intellisense: no operator"<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char> <<std::string
I understand what its saying, but jumble is a std::string
Here are my preprocessor directives and using statements
Code:
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
View 4 Replies
View Related
Sep 20, 2012
class CPop {
CBSVector<CTour> pop;
CBSVector<double> probability;
int popsize;
double TotalFitness;
CTour Elite;
CTspGAParams GAParameters;
}
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
I don't know y these errors, it runs fine in simple c++ environment
View 14 Replies
View Related