Thread: Error - Does not have a class type

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    100

    Error - Does not have a class type

    I'm getting an error when I attempt compiling my program. I left out the block.cc/h files because they don't pertain to the problem at hand at the moment. I'm building a cache simulator but the problem I'm currently facing does not have much to do with the cache end of things, but more so C++ syntax mainly vectors. When I compile I get the following error :

    -bash-4.1$ g++ simulation.cc
    In file included from simulation.cc:1:
    cache.cc: In constructor âCache::Cache(int, int, int, int, int)â:
    cache.cc:23: error: â((Cache*)this)->Cache::vâ does not have class type
    cache.cc: In member function âint Cache::read(long unsigned int)â:
    cache.cc:39: error: â((Cache*)this)->Cache::vâ does not have class type

    Any pointers would be greatly appreciated, thank you very much!

    Here are the files containing my code:

    simulation.cc
    Code:
    #include "cache.cc"
    
    int main(){
     int M = 32;
     int C = 1024;
     int B = 2;
     int E = 1;
     int S = 4;
     int m = 4;
     // there are 4 block offset bits (b)
     
     
     // calculated in other classes as needed?
     //int S = 
     //int t = 
     //int s = //# of set index bits
     //int b = //# of block offset bits
     
     Cache* cache = new Cache(M,C,B,E,S);
     
     cache->read(0);
     cache->read(1);
     cache->read(2);
     cache->read(3);
     
     cache->read(0);
     cache->read(1);
     cache->read(2);
    }
    cache.cc
    Code:
    Cache::Cache() {
    //instance variables
      M = 0;
      C = 0;
      B = 0;
      E = 0;
      S = 4;
      vector<set*> v(S); // holds list of sets
    }// Constructor
    Cache::Cache(int mainMemSize, int cacheSize, int blockSize, int numOfLinesPerSet,
     int numOfSets) {
      int M = mainMemSize;  //size of main memory address space (m in the book)
      int C = cacheSize;  //size of cache in bytes(C in book)
      int B = blockSize;  //size of blocks(B in the book)
      int E = numOfLinesPerSet; //set associativity (E in the book) - is the number of cache lines/blocks per set
      int S = numOfSets;
      vector<set*> v(S);
      for(int i = 0; i < numOfSets; i++){
       this->v.at(i) = new set();
      }
    }
     
     int Cache::read(unsigned long memAddress){
     // split address into 3 sections - tag, set index, and block index
     // works for 32 bit?
     int offset = (memAddress >> 0) & ((1 << 6) -1);
     int setIndex = (memAddress >> 6) & ((1 << 5) -1);
     int tag = (memAddress >> 11) & ((1 << 21) -1);
     int validBit = 0; // 1 or 0 based on if block is used or not
     
     //use set index to call right set
     int hitFlag = v.at(0)->set.read(offset, tag);
     
     
     
     
     if (hitFlag = 0) {
      return hitFlag; // if cache hit
     } else if (hitFlag = 1) {
      // return 1 if cache miss
     } else {
      // return 2 if cache miss with a write back on eviction
     }
     }
     int Cache::write(unsigned long memAddress){
    
     
      return 0; // if cache hit
          // return 1 if cache miss
          // return 2 if cache miss with a write back on eviction
     }
     
     int dumpCache(){
     
     
     //return # of cache values needed to be written back to main memory
     }
     
     void Cache::display() {
     //cout for debug purposes
     cout << "Main Memory Size is : " << this->M << "\n";
     cout << "Cache size is : " << this->C << "\n";
     cout << "Block size is : " << this->B << "\n";
     cout << "Number of lines per set is : " << this->E << "\n";
     //cout << "Main Memory Size is : " << this.S << "\n";
     }
    cache.h
    Code:
    #include "set.cc"
    class Cache {
    private:
      int M;
      int C;
      int B;
      int E;
      int S;
      vector<set*> v(); // holds list of sets
    public:
      Cache();
      Cache(int mainMemSize, int cacheSize, int blockSize, int numOfLinesPerSet, int numOfSets);
      int read(unsigned long memAddress);
      int write(unsigned long memAddress);
      void display();
    };
    set.cc
    Code:
    #include "set.h"
    set::set() {
    //instance variables
      E = 0;
      vector<block*> v(E); // holds list of lines/blocks
      validBit = 0;
    }
    
    // Constructor
    set::set(int E, int validBit) {
     this->E = E;
     this->validBit = validBit;
    }
     
     int set::read(int offset, int tag){
      //ve.push_back();
     
      return 0; // if cache hit
          // return 1 if cache miss
          // return 2 if cache miss with a write back on eviction
     }
    
     int set::write(int offset, int tag){
    
     
      return 0; // if cache hit
          // return 1 if cache miss
          // return 2 if cache miss with a write back on eviction
     }
     
     
     /*void set::display() {
      //cout for debug purposes
     }*/
    set.h
    Code:
    #include "block.cc"
    class set {
    private:
      int validBit;
      int E;
      vector<block*> v(); // holds list of lines/blocks
    public:
      set();
      set(int E, int validBit);
      int read(int offset, int tag);
      int write(int offset, int tag);
    };

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    #include "cache.cc"
    don't #include the implementation in the header.
    Kurt

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    don't #include the implementation in the header.
    O_o

    ... and even when the implementation must be available, such as templates, the declaration of a class must be available before you separately implement the components.

    That said, your arrangement of dependencies looks confusing. You could do better.

    Soma

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    100
    The problem I'm currently trying to solve is the one on this line in cache's read function: int hitFlag = v.at(0)->set.read(offset, tag);
    and my loop initializing all the sets in the constructor:
    Code:
    for(int i = 0; i < numOfSets; i++){
          this->v.at(i) = new set();
      }
    I'm getting this error:

    -bash-4.1$ g++ simulation.cc
    In file included from simulation.cc:1:
    cache.cc: In constructor âCache::Cache(int, int, int, int, int)â:
    cache.cc:23: error: â((Cache*)this)->Cache::vâ does not have class type
    cache.cc: In member function âint Cache::read(long unsigned int)â:
    cache.cc:39: error: â((Cache*)this)->Cache::vâ does not have class type

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Include only class definitions. Do not include implementations.
    Why are you using new here? I don't see the need for it. The rule of thumb is: if you can get away with it, then don't use new. The end.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I'm getting this error:
    O_o

    Well, it would; that `v' isn't a a class type. (Hint: That `v' is a function.)

    *shrug*

    Fixing that bug, you have still more, and semantic, logical, and implementation issues besides.

    I didn't realize when I looked over the order and relation of includes that your code too was so borked.

    In producing this code, you've outpaced your knowledge and skill. You'll continue to have more and more difficulties as you try and debug this code.

    Do yourself a favor; return to simpler programs for a time so you can build a larger foundation of skill and knowledge through practice.

    Specifically, start with nailing down classes; you need to spend more effort learning how member variables work and how to they are initialized through construction.

    Soma

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Adding to that...

    - Member variable names are poor at best; indentation is insufficient or poor. Use 4 spaces or 1 tab for indentation. Not one space.
    - Don't confuse assignment and comparison (= vs ==).

    >>vector<block*> v(); // holds list of lines/blocks
    The "()" at the end makes this a function that takes no parameters and returns a vector of block pointers (they shouldn't be pointers!).
    Don't confuse functions with variables. A good tip is to never use parentheses unless you have one or more parameters to pass to the constructor of the object you are constructing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Setting out to "nip it in the bud": no one is trying to offend you; we all know for what you are shooting; you are not entitled to support; we do not do work for you. The above is just an assessment of your skill, knowledge, and code. We will happily help you and your code improve, but you are going to need to show the effort.

    *shrug*

    Now, I'm not saying this is you, and it isn't my nature to rescue people, but I am saying this as kind of a warning not to take your thread down a bad path.

    Soma

  9. #9
    Registered User
    Join Date
    Feb 2013
    Posts
    100
    Quote Originally Posted by phantomotap View Post
    O_o

    Setting out to "nip it in the bud": no one is trying to offend you; we all know for what you are shooting; you are not entitled to support; we do not do work for you. The above is just an assessment of your skill, knowledge, and code. We will happily help you and your code improve, but you are going to need to show the effort.

    *shrug*

    Now, I'm not saying this is you, and it isn't my nature to rescue people, but I am saying this as kind of a warning not to take your thread down a bad path.

    Soma
    I really appreciate all the help, but my four files of code isn't effort enough? Believe me I'm putting in the effort, I'm really new to C++

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I really appreciate all the help, but my four files of code isn't effort enough?
    Well, all the regulars who may help you have different standards, but that's really yet to be determined in the general sense.

    But, I'm willing to be moved.

    You've been handed several clear instruction. Do you wish to proceed? Let's see your current code; specifically, let's see your code after you've followed those instructions or at least shown real effort in following those instructions.

    Believe me I'm putting in the effort, I'm really new to C++
    This is exactly my point; you've bitten off far, far more than you can chew.

    In the past few weeks we have evidence that you have tried to consume sockets, applications with multiple threads, applications composed of multiple processes, data structures, and file format design and implementation.

    Your plate is already overfull, and now you are trying to add C++ where mostly your code has been C.

    You aren't going to manage all of this at the same time. Period.

    The effort I'm referring to isn't simply a matter of "Throw code and ideas at the CBoard regulars.". (*) We aren't responsible for helping you piecemeal your projects.

    While every regular has different standards, virtually all of us only support this community to help spread the knowledge and skills C and such programmers need.

    Now, I've already noticed this piecemeal attempt, and now still more will take note, but maybe that doesn't mean anything to them, but for me, I'm waiting on you to slow down and focus. You will not really learn ........, at least not enough to support yourself, while trying to consume so much, so fast.

    Soma

    (*) "Seaboard Regulars" sounds like the most nerd band of pirates ever!
    Last edited by phantomotap; 04-22-2013 at 06:46 PM.

  11. #11
    Registered User
    Join Date
    Feb 2013
    Posts
    100
    What you are seeing is me in the early stages still fiddling with concepts giving a first shot at things and I throw it on here to kind of get other peoples' feedback, I only do this when I'm not expecting to get assistance for at least a day in person. You guys have really given me that extra boost I need to get through all the subjects I'm covering in the courses I'm taking at the moment. Normally I wouldn't be covering so many topics but I'm taking more computer science courses than I ought to be, but this online board really helps solve that increased need for assistance. Again, I can't thank you guys enough for all the help you've given me with all my various projects.

  12. #12
    Registered User
    Join Date
    Feb 2013
    Posts
    100
    I removed the parentheses making the vectors actually instance variables rather than functions, but that line is still giving me a problem:
    In file included from simulation.cc:1:
    cache.cc: In constructor âCache::Cache(int, int, int, int, int)â:
    cache.cc:22: error: invalid use of member (did you forget the â&â ?)
    -bash-4.1$

  13. #13
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Two things...

    1): Those bits of bold from an earlier post was not me practicing how to add bold face to my posts.
    2): The suggestion that you post your code after following the instructions Kurt, Elysia, and I laid out wasn't really a suggestion it was more of a suggestion.

    Soma

  14. #14
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    It would probably be safer not to call one of your things "set".
    Judging by one of your header files, you have a using namespace std in there somewhere since you're not explicitly qualifying std::vector, and this is just begging for a conflict with std::set.

    When you have a moment, look up constructor initialisation lists. Your constructor could look like this, which tends to be more efficint in general, as well as much shorter:
    Code:
    set::set(int E, int validBit) : E(E), validBit(validBit) {}
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-27-2013, 07:52 AM
  2. Replies: 5
    Last Post: 07-24-2012, 04:25 AM
  3. Replies: 3
    Last Post: 07-08-2008, 10:01 AM
  4. Getting a:"member is not of class type" error
    By indigo0086 in forum C++ Programming
    Replies: 10
    Last Post: 11-20-2006, 10:19 AM
  5. Error using string class type
    By matth in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2006, 05:52 PM