locked
code help RRS feed

  • Question

  • i get this error

    1>c:\users\packard bell\documents\visual studio 2010\projects\jjjjjjj\jjjjjjj\stdafx.h(14): error C2143: syntax error : missing ';' before '<class-head>'

    when i run the following error

    // stdafx.h : include file for standard system include files,

    // or project specific include files that are used frequently, but

    // are changed infrequently

    //

     

    #pragma

     

     

    once

     

    #include

     

     

    "targetver.h"

     

    #include

     

     

    <stdio.h>

    #include

     

     

    <tchar.h>

     

     

    int ref class

    jjj

    {

    public

     

     

    :

    jjj(

     

    void

    );

    };

     

     

    // TODO: reference additional headers your program requires here;

    Monday, April 11, 2011 9:21 PM

Answers

  • The "ref" keyword is only meaningful in C++/CLI,
    which means it needs the CLR. You will get an
    error if compiling as C++ without the CLR as
    C++ doesn't recognize the "ref" keyword.

    If you're going to use the C++/CLI then you should
    have used one of the CLR project templates. If you're
    not going to use C++/CLI, just standard C++, then
    remove the "ref" from the class.

    If you want to use C++/CLI from the existing project, go
    to your Project Properties->Configuration Properties:
    "General" and under "Common Language Runtime support"
    set it to "Common Language Runtime Support (/clr)".

    - Wayne
    • Marked as answer by Rob Pan Tuesday, April 19, 2011 2:17 AM
    Tuesday, April 12, 2011 4:51 PM
  • Since your original problem has been solved, you should
    have marked my reply as "Answer" and then started a new
    thread for this new problem. It is not related to the
    original issue.

    >d.cpp(1): fatal error C1083: Cannot open include file: 'd.h':
    >No such file or directory

    The error message tells you which source code file has
    the problem, and which line number in that file. The
    code you posted is not related to this error. It is not
    from the correct source code.

    Look at line 1 of d.cpp and see what you have there.
    If you have a statement such as

    #include "d.h"
    or
    #include <d.h>

    then *you* have to provide that header file.

    - Wayne
    • Marked as answer by Rob Pan Tuesday, April 19, 2011 2:17 AM
    Wednesday, April 13, 2011 7:46 PM
  • How do you think we can help with coding errors without
    seeing any code? Show the source for jjjjjjj.cpp

    The linker errors are telling you that you have referred to
    something (jjj::.ctor) in both jjjjjjj.cpp and stdafx.cpp
    for which you have not provided any implementation. This
    usually indicates that you have *declared* something -
    such as a class constructor - but you have never *defined*
    it by providing the actual implementation body.

    - Wayne
    • Marked as answer by Rob Pan Tuesday, April 19, 2011 2:18 AM
    Wednesday, April 13, 2011 8:05 PM

All replies

  • // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    //
    
    #pragma once
    
    #include "targetver.h"
    
    #include <stdio.h>
    #include <tchar.h>
    
     int ref class jjj
    {
    public:
    	jjj(void);
    };
    
    
    
    // TODO: reference additional headers your program requires here;
    
    Monday, April 11, 2011 9:23 PM
  • >int ref class jjj
    >{

    Why do you have int there?

    - Wayne
    Monday, April 11, 2011 10:50 PM
  • Note that class definitions, constructors, and
    destructors, don't have a return type. Member
    functions do.

    - Wayne

    Monday, April 11, 2011 10:55 PM
  • why without int everything is underlined by red line

    you tell me exactly where i have to add ; so that i can the program the error message is againg given below

    c:\users\packard bell\documents\visual studio 2010\projects\jjjjjjj\jjjjjjj\stdafx.h(16): error C2143: syntax error : missing ';' before '<class-head>'

     

    Tuesday, April 12, 2011 4:25 PM
  • The "ref" keyword is only meaningful in C++/CLI,
    which means it needs the CLR. You will get an
    error if compiling as C++ without the CLR as
    C++ doesn't recognize the "ref" keyword.

    If you're going to use the C++/CLI then you should
    have used one of the CLR project templates. If you're
    not going to use C++/CLI, just standard C++, then
    remove the "ref" from the class.

    If you want to use C++/CLI from the existing project, go
    to your Project Properties->Configuration Properties:
    "General" and under "Common Language Runtime support"
    set it to "Common Language Runtime Support (/clr)".

    - Wayne
    • Marked as answer by Rob Pan Tuesday, April 19, 2011 2:17 AM
    Tuesday, April 12, 2011 4:51 PM
  • thanks for your help but now i got another error

    1>d.cpp(1): fatal error C1083: Cannot open include file: 'd.h': No such file or directory

    i changed the code acording to your sugesstion an that problem was solved . the new code is

    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    //
    
    ;
    
    #pragma once
    
    #include "targetver.h" 
    
    #include <stdio.h> 
    #include <tchar.h> 
    
     ref class jjj 
    {
    public:
    	jjj(void);
    } 
     ;
     
    
    
    
    // TODO: reference additional headers your program requires here;
    
    and tell me what code i should i add in the new file d.h
    Wednesday, April 13, 2011 7:32 PM
  • Since your original problem has been solved, you should
    have marked my reply as "Answer" and then started a new
    thread for this new problem. It is not related to the
    original issue.

    >d.cpp(1): fatal error C1083: Cannot open include file: 'd.h':
    >No such file or directory

    The error message tells you which source code file has
    the problem, and which line number in that file. The
    code you posted is not related to this error. It is not
    from the correct source code.

    Look at line 1 of d.cpp and see what you have there.
    If you have a statement such as

    #include "d.h"
    or
    #include <d.h>

    then *you* have to provide that header file.

    - Wayne
    • Marked as answer by Rob Pan Tuesday, April 19, 2011 2:17 AM
    Wednesday, April 13, 2011 7:46 PM
  • i got out of this error now there's another error

    1>------ Build started: Project: jjjjjjj, Configuration: Release Win32 ------

    1> LINK : /LTCG specified but no code generation required; remove /LTCG from the link command line to improve linker performance

    1>stdafx.obj : error LNK2020: unresolved token (06000001) jjj::.ctor

    1>jjjjjjj.obj : error LNK2020: unresolved token (06000001) jjj::.ctor

    1>C:\Users\Packard bell\documents\visual studio 2010\Projects\jjjjjjj\Release\jjjjjjj.exe : fatal error LNK1120: 2 unresolved externals

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Wednesday, April 13, 2011 7:54 PM
  • How do you think we can help with coding errors without
    seeing any code? Show the source for jjjjjjj.cpp

    The linker errors are telling you that you have referred to
    something (jjj::.ctor) in both jjjjjjj.cpp and stdafx.cpp
    for which you have not provided any implementation. This
    usually indicates that you have *declared* something -
    such as a class constructor - but you have never *defined*
    it by providing the actual implementation body.

    - Wayne
    • Marked as answer by Rob Pan Tuesday, April 19, 2011 2:18 AM
    Wednesday, April 13, 2011 8:05 PM