Worst C++ error I've had

Show off new creations, get help, or just chat about all aspects of web development and design.

Worst C++ error I've had

Postby Spike on Sat May 09, 2009 4:39 pm

The following error is driving me nuts. It's a very weird error I don't understand why it's happening.

First I'll show you my class:

header:
Code: Select all
#ifndef LABERINT_HPP
#define LABERINT_HPP

#include <cmath>
#include "Arbol.hpp"
using namespace std;

class Laberint {
   
private:

   typedef struct {
      int id;
      int dist_esq;
      int dist_dret;
      int porta_esq;
      int porta_dret;
   }sala;
   
   Arbol<sala> a;
      
   typedef struct {
      double t;
      int mcr_final;
   }t_i_mcrfinal;
   
   typedef struct {
      bool d;
      bool vel;
      bool atrapat;
   }direc_vel;

public:
   Laberint();
   ~Laberint();
   direc_vel calcular_dir_i_vel(sala s,int mcr,int mcr_actual,int v);
   t_i_mcrfinal millor_temps(double t_e,double t_d,int mcr_e,int mcr_d);

};

#endif


cpp:

Code: Select all
direc_vel Laberint::calcular_dir_i_vel(sala s,int mcr,int mcr_actual,int v)
{
 direc_vel x;
some code here
return x;
}

t_i_mcrfinal Laberint::millor_temps(double t_e,double t_d,int mcr_e,int mcr_d)
{
   t_i_mcrfinal x;
   x.t = t_e;
   x.mcr_final = mcr_e;
   return x;
}


The errors I get are:
Code: Select all
Laberint.cpp:6: error: ‘direc_vel’ does not name a type
Laberint.cpp:82: error: ‘t_i_mcrfinal’ does not name a type
User avatar
Spike
May Contain Skills
May Contain Skills
 
Joined: Wed Sep 17, 2008 7:10 pm

Re: Worst C++ error I've had

Postby davidc538 on Sat May 09, 2009 5:06 pm

whenever I get crap like this I can't understand I just google it and it gets sorted pretty quick, for this one I would just punch in "does not name a type" or "C++ does not name a type".
See what I mean?
User avatar
davidc538
Been Here A While
Been Here A While
 
Joined: Mon Aug 11, 2008 4:27 pm

Re: Worst C++ error I've had

Postby Spike on Sat May 09, 2009 5:11 pm

Yeah, I've been doing it for 2 days without any result :S
User avatar
Spike
May Contain Skills
May Contain Skills
 
Joined: Wed Sep 17, 2008 7:10 pm

Re: Worst C++ error I've had

Postby Angry Beaver on Wed Jun 24, 2009 11:19 pm

spike, your using your struct wrong

struct PERSON { // Declare PERSON struct type
int age; // Declare member types
long ss;
float weight;
char name[25];
} family_member; // Define object of type PERSON

the way you have it your creating something called direc_vel and trying to use that variable as the return parameter in your functions rather than giving the struct the type of direc_vel. as your trying to return a variable its getting confused and not thinking its a return type.
"To repeat what others have said and done, requires education; to challenge it, requires brains; to improve it requires skill and luck."
Angry Beaver
Sir Post-a-lot
Sir Post-a-lot
 
Joined: Thu Jan 24, 2008 9:18 pm

Re: Worst C++ error I've had

Postby zombie@computer on Thu Jun 25, 2009 7:13 am

you can use typedef with structs (allthough there is little need) but then you would still need to declare teh struct itself

typedef struct myvar {
int data1;
int data2;
char data3;
} newtype;

also, not sure if c is going to bitch about it, but you are trying to return a private variable from a public member function. just fyi
When you are up to your neck in shit, keep your head up high
User avatar
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Return to Web Design & Development

Who is online

Users browsing this forum: No registered users