Can not reach the classes and create instances of them

This is a discussion on Can not reach the classes and create instances of them within the C++ Programming forums, part of the General Programming Boards category; Hello everybody, I have some files both .cpp and .h that are coded in C++ by someone else before(only 5 ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    Ankara, Turkey
    Posts
    18

    Unhappy Can not reach the classes and create instances of them

    Hello everybody,

    I have some files both .cpp and .h that are coded in C++ by someone else before(only 5 files that creates a Binary Search Tree). I would like to use it in my project.

    First of all, I have copied the files that I need to the same directory of my .cpp file that contains the main method. Then, I have added the files using, Add> Add Existing Item from Visual Studio 2003.NET. Then, click build and compile, compiler did not give any error or warnings and compiled successfully. Nevertheless, when I want to create an object from a class from my main method compiler does not see any classes.

    I have spent my day on this but couldn't go one step further, any help would be appriciated.

    If you want I can send the project file who wants to help, it is so small, and I only need why it does not see the classes.

    Code:
    // ********************************************************
    // Header file TreeException.h for the ADT binary tree.
    // ********************************************************
    #include <stdexcept>
    #include <string>
    using namespace std;
    
    class TreeException: public logic_error
    {
    public:
       TreeException(const string & message = "")
                            : logic_error(message.c_str())
       { }
    };  // end TreeException

    Kind Regards,
    Attached Files Attached Files
    Sarp Arda Coskun
    www.bilgiciftligi.com

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,659
    >> when I want to create an object from a class from my main method compiler does not see any classes
    No one knows what that means. What exactly are you having problems with? Does it not compile? What are the compiler errors? Does it not run correctly? In what way?

    gg

  3. #3
    Registered User
    Join Date
    Dec 2004
    Location
    Ankara, Turkey
    Posts
    18
    It does compile without any error when you do not create an instance of a class. However, when you try to create an object, it gives error such as;

    d:\directory\driver.cpp(10): error C2065: 'BinarySearchTree' : undeclared identifier
    d:\directory\driver.cpp(10): error C2146: syntax error : missing ';' before identifier 'myTree'
    d:\directory\driver.cpp(10): error C2065: 'myTree' : undeclared identifier

    Can you help?
    Sarp Arda Coskun
    www.bilgiciftligi.com

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    d:\directory\driver.cpp(10):
    Post that code along with a few lines above and below it.

  5. #5
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    The problem is that you are adding the files to your project, but you are not including the header in your source file. In your source file you are going to need to add the header that delcares the object you are trying to instantiate. ex:

    #include "someheader.h"

    my guess would be the BST.h
    Last edited by Darryl; 04-11-2005 at 07:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of classes?
    By dream_noir in forum C++ Programming
    Replies: 2
    Last Post: 03-22-2009, 11:43 AM
  2. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  3. Create generic classes to be specified later?
    By jmd15 in forum C++ Programming
    Replies: 18
    Last Post: 08-05-2007, 09:21 AM
  4. Learning how to use classes and create header files
    By Welshy in forum C++ Programming
    Replies: 10
    Last Post: 04-19-2005, 12:33 PM
  5. Instances of classes
    By JasonLikesJava in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2002, 12:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21