Thread: Creating a class instance (am i going insane?!)

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    117

    Creating a class instance (am i going insane?!)

    Here is the code, tried fixing it for a hour now...

    I get
    Code:
    |12|error: 'Transmittance' was not declared in this scope
    |12|error: expected ';' before 'PropylAcetate'
    Thank you for returning my sanity!

    main.cpp:
    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    #include "reinterpret.h"
    #include "Transmittance.h"
    
    using namespace std;
    
    int main()
    {
        Transmittance PropylAcetate(3696);
    
        return 0;
    }
    Transmittance.cpp
    Code:
    #include "Transmittance.h"
    
    Transmittance::Transmittance(int SIZE)
    {
        ifstream ifs ("jon_spec.SPA", ios::in|ios::binary);
    
        if (ifs.is_open())
        {
            TransmittancePercent* = new float [SIZE];
    
            ifs.seekg (0x568, ios::beg);
            ifs.read( addr(TransmittancePercent), sizeof(TransmittancePercent) );
            ifs.close();
        }
    
        else
        {
            cout << "Unable to open SPA file";
        }
    
    }
    Transmittance.h
    Code:
    #define TRANSMITTANCE_H
    #ifndef TRANSMITTANCE_H
    
    #include <iostream>
    using namespace std;
    
    
    class Transmittance
    {
        private:
        float* TransmittancePercent;
        float start, end, multiple;
        int size;
    
        public:
        Transmittance(int);
    
    };
    
    
    #endif
    My Ctrl+S addiction gets in the way when using Code Blocks...

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Quote Originally Posted by JonathanS View Post
    Code:
    #define TRANSMITTANCE_H
    #ifndef TRANSMITTANCE_H
    
    /* ... */
    
    #endif
    Those first two statements are the wrong way around - the #ifndef will always be false, so the code that declares the class will never be seen by the compiler.
    Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)

    ~~~

    "The largest-scale pattern in the history of Unix is this: when and where Unix has adhered most closely to open-source practices, it has prospered. Attempts to proprietarize it have invariably resulted in stagnation and decline."

    Eric Raymond, The Art of Unix Programming

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    117
    Silly me, thanks!
    My Ctrl+S addiction gets in the way when using Code Blocks...

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    On a side note, it's poor style to have "using namespace" in a header.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Declaring an instance of a class inside a class
    By nickodonnell in forum C++ Programming
    Replies: 4
    Last Post: 10-01-2005, 11:46 PM
  2. creating class instance from a file
    By Callith in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2004, 09:03 PM
  3. pointer to an instance of a different class
    By xlix in forum C++ Programming
    Replies: 4
    Last Post: 07-24-2003, 04:19 PM
  4. creating a new instance of a function?
    By Geolingo in forum C++ Programming
    Replies: 17
    Last Post: 07-18-2003, 09:39 AM
  5. Instance of a class returning itself
    By Boksha in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2002, 11:14 AM