Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Compliments on a fantastic web site. I have learned so much from my threads and even if sometimes I cannot solve the problem, it gives me the reassurance that I am not the only one putting up with it!..."

Geography

Where in the world do Tek-Tips members come from?

Creating a constructor with a string parameterHelpful Member! 

fatlardo (Programmer)
26 Nov 07 8:27
I am new to C++ and I think I may have thrown myself in a bit too deep!! I have programmed before in Delphi and Java so I think this may be more of a syntaxical problem.

I am trying to create a class and, on calling the constructor, pass a filename to the constructor. As it stands I'm trying to use a string variable.

The problem I get is that I get errors in my header and source file. In the header file, I get the error field 'string' has incomplete type. In my source file I have the error expected ')' before 'filename'.

The code I am using is below. Anyone got any ideas of the problem?

I'm using Eclipse if that helps anyone!

Bitmap.h

#ifndef BITMAP_H_
#define BITMAP_H_

namespace gary_media
{

class Bitmap
{
public:
    Bitmap(string);
    virtual ~Bitmap();
private:
    int * image;
    int imgHeight, imgWidth;
};

}

#endif /*BITMAP_H_*/

Bitmap.cpp

#include "Bitmap.h"
#include <cstdio>
#include <string>

//using namespace gary_file;

namespace gary_media
{

Bitmap::Bitmap(string filename)
{
    if (filename == "") {
        return;
    }
    
    if (!FileExists(filename)) {
        return;
    }
    
    FILE * pFile;
    pFile = fopen ("/home/gary/Desktop/test.txt", "r");
}

Bitmap::~Bitmap()
{
}

}
Helpful Member!  PerFnurt (Programmer)
26 Nov 07 10:26
Put the

CODE

#include<string>
into the .h file instead.



And refer to it winth the std namespace.
And make it a const ref.

Ie

CODE


#include<string>

  .
  .
  .

class Bitmap
{
public:
    Bitmap(const std::string&);
  .
  .
  .
 

/Per

www.perfnurt.se

fatlardo (Programmer)
26 Nov 07 11:23
Thanks a lot. It works now :D

You'll probably hear from me again before the end of the week!!

Thanks

Gary

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close