473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C++ Constructor help. Please help.

2
Can someone please show me how I would create these constructors in the source file...my compiler tells me I have errors. I know I set up my main, header, and source file correctly because I am getting no errors until I start implementing the constructors.

In the HEADER file:(xArray.h)
class xArray{
public:
//constructors
xArray();
xArray(const xArray& a);
xArray(const int x);
private:
size_t len;
size_t size;
//data of int array
int *data;
};

In the source file: (xArray.cpp)

//this is the constructor I am unsure about
xArray::xArray(const xArray& a){
// ? ? ? ? ? ? ? ? ?
}


//these two constructors I believe are correct...my compiler does not return any
//errors

//constructor 1
xArray::xArray(){
len = 0;
size = 0;
data = new int[size];
}

//constructor 3
xArray::xArray(const int x){
len = 0;
size = x;
data = new int[x];
}

All help is greatly appreciated.
Oct 14 '08 #1
3 1334
gpraghuram
1,275 Expert 1GB
What error you are getting?

Raghu
Oct 14 '08 #2
izzyk
2
What error you are getting?

Raghu
Ok, I think I've created all three of my constructors correctly now: But when I try to create a new xArray in my MAIN file (xArray a;), I am getting an error: (the error is posted below after the constructors which are directly below this.)

//constructor 1
xArray::xArray(){
len = 0;
size = 0;
data = new int[size];
}

//constructor 2
xArray::xArray(const xArray& a){
len = a.len;
size = len*2;
data = new int[size];
}

//constructor 3
xArray::xArray(const int x){
len = 0;
size = x;
data = new int[x];
}



//MAIN.cpp

cout << "Testing the constructors." << endl;
xArray a; //trying to create an xArray

HERE IS THE ERROR I AM GETTING: (USING VISUAL BASIC C++):
MAIN.obj : error LNK2019: unresolved external symbol "public: _thiscall xArray::~xArray(void)" (??1xArray@@QAE@XZ) referenced in function_main
MAIN.exe : fatal error LNK1120: 1 unresolved externals
Oct 14 '08 #3
gpraghuram
1,275 Expert 1GB
Have you declared the destructor in header and not defined the body for it?

Raghu
Oct 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Alfonso Morra | last post by:
Hi, I have some code from an example, that I want to retrofit into my project. The code from the example has the following line: SharedAppenderPtr myAppender( new...
9
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all. I am in the process of teaching myself C# and I think I am doing OK. I have learnt how to how to call the right constructor of a...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
7
by: gopal | last post by:
Can one constructor of a class call another constructor of the same class to initialize the this object? I read in the FAQ , to the above question the following ans was given Nope. Let's...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.